Qt小部件获得焦点时获取通知/事件/信号 [英] Get a notification/event/signal when a Qt widget gets focus
本文介绍了Qt小部件获得焦点时获取通知/事件/信号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
您可以添加en 事件过滤器
。
这是使用 QtCreator 编写的应用程序示例。该表单有一个名为 combobox 的 QComboBox 。
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;
}
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?
解决方案
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屋!
查看全文