当 Qt 小部件获得焦点时获取通知/事件/信号 [英] Get a notification/event/signal when a Qt widget gets focus
本文介绍了当 Qt 小部件获得焦点时获取通知/事件/信号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 Qt 中,当小部件获得焦点时,如何获得有关它的通知,以便我可以执行一些自定义代码?是否有信号或事件?
In Qt, when a widget receives focus, how can get a notification about it, so I can execute some custom code? Is there a signal or an event for that?
推荐答案
您可以添加en事件过滤器
.
这是使用 QtCreator 编写的应用程序示例.此表单有一个名为 combobox 的 QComboBox.
You can add en event filter
.
This is an example of an application written with QtCreator. This form has a QComboBox named combobox.
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->comboBox->installEventFilter(this);
.
.
.
}
bool MainWindow::eventFilter(QObject *object, QEvent *event)
{
if (event->type() == QEvent::FocusOut)
{
if (object == ui->comboBox)
{
qWarning(object->objectName().toLatin1().data());
}
}
return false;
}
这篇关于当 Qt 小部件获得焦点时获取通知/事件/信号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文