class QtWidgetsApplication1 : public QMainWindow
{
Q_OBJECT
public:
QtWidgetsApplication1(QWidget *parent = nullptr);
~QtWidgetsApplication1();
private:
Ui::QtWidgetsApplication1Class ui;
public slots:
void changelabel();
};
QtWidgetsApplication1::QtWidgetsApplication1(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
QObject::connect(ui.pushButton, SIGNAL(pressed()),this, SLOT(changelabel()));
}
void QtWidgetsApplication1::changelabel()
{
ui.label->setText(QString("clicked"));
}
class GlobalEventFilter : public QObject
{
public:
virtual bool eventFilter(QObject* watched, QEvent* event) override
{
qDebug() << "watched : " << watched << " event : " << event->type();
return false;
}
};
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QtWidgetsApplication1 w;
a.installEventFilter(new GlobalEventFilter());
w.show();
return a.exec();
}
标签:事件处理,QtWidgetsApplication1,Qt,parent,QObject,ui,changelabel,public
From: https://www.cnblogs.com/DesertCactus/p/18418453