QT 为按钮添加事件
来源:互联网 发布:淘宝助理5.8使用教程 编辑:程序博客网 时间:2024/05/21 09:14
-.在vs2010环境中。
在QT designer中为helloword.ui添加pushbutton
,返回vs
(1):第一种方式:
在helloword.h中添加:
public slots:
void ClickButton();
在helloword.cpp中:
构造函数中添加:
connect(ui.button_exit, SIGNAL(clicked()), this, SLOT(ClickButton()));
并定义方法:
void helloword::ClickButton()
{
//what you want to do
//QMessageBox::information(this, "My Tittle", "Hello World!");
ui.button_exit->setText(tr("(adgkl;kj)"));
}
(2).第二种方式:
.h中添加:
protected:
bool eventFilter(QObject *target, QEvent *e);
.cpp中添加:
bool helloword::eventFilter(QObject *target, QEvent *e)
{
if(target == ui.button_exit)
{
if(e->type() == QEvent::MouseButtonDblClick) //双击消息
QMessageBox::about(this,"x","x");
}
return QMainWindow::eventFilter(target, e);
}
(3).第三种方式:
.h中添加
public slots:
void myExitButtonFuc();
.cpp中添加:
void helloword::myExitButtonFuc()
{
ui.button_exit->setText(tr("(myExitButtonFunc)"));
}
在ui中为button添加信号槽:
配置槽的参考:
二:单独使用qt creator
- QT 为按钮添加事件
- QT 为按钮添加事件
- QT 为按钮添加事件
- QT 为按钮添加事件
- 为按钮添加监听事件
- QT用信号和处理机制为事件添加处理动作(点击按钮显示helloworld)
- Qt为QLabel添加点击事件-使QLabel成为一个图片按钮
- Android为按钮添加相应事件
- Android开发--为按钮添加点击事件
- 为每个按钮添加Click事件
- 为按钮添加鼠标的事件监听器
- 【Android studio】为按钮添加简单事件
- QT为QLabel添加Click事件
- QT为QLabel添加Click事件
- QT为QLabel添加Click事件
- QT事件处理(以按钮为例子)
- QT事件处理(以按钮为例子)
- QT 环境下为按钮菜单项添加快捷键
- web项目的发布(tomcat eclipse spring)
- 基于Dubbo框架构建分布式服务
- Android单元测试(四):Robolectric框架的使用
- 容器
- Fiddler模拟弱网(4)
- QT 为按钮添加事件
- MUI + Android 的初次使用
- spring学习----注解描述
- opencv 函数用法
- JSP文本框中默认带出当前系统日期
- Lucene的索引文件格式
- 定位一组元素 和 iframe
- Centos7部署单机版Hadoop做测试
- 数据结构 【1】 顺序表