widget.h
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28#ifndef WIDGET_H #define WIDGET_H #include <QWidget> #include <QDebug> namespace Ui { class Widget; } class Widget : public QWidget { Q_OBJECT public: int number = 0; explicit Widget(QWidget *parent = 0); ~Widget(); bool eventFilter(QObject *obj, QEvent *e); private: Ui::Widget *ui; }; #endif // WIDGET_H
widget.cpp
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39#include "widget.h" #include "ui_widget.h" Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget) { ui->setupUi(this); ui->textEdit->setAttribute(Qt::WA_Hover,true);//开启悬停事件 ui->textEdit->installEventFilter(this); } Widget::~Widget() { delete ui; } bool Widget::eventFilter(QObject *obj, QEvent *e) { if(obj == ui->textEdit) { //if(e->type() == QEvent::Wheel) if(e->type() == QEvent::HoverEnter) { qDebug() << "helloworld!"; qDebug() << number++; } } }
最后
以上就是负责外套最近收集整理的关于QT 给控件添加事件过滤的全部内容,更多相关QT内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复