Get a notification/event/signal when a Qt widget gets focus
Get a notification/event/signal when a Qt widget gets focus
Qt widget gets focus on event filter.
The application written with the QtCreator and form the 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; }
The level of WYSIWYG programe is:
In C++,
class LineEdit : public QLineEdit { virtual void focusInEvent( QFocusEvent* ) {} };
The alternative answer is:
By focusChangedsignal through sending by the focus changes and has two arguments one is widget losing focus and the one is gaining focus.
void QApplication::focusChanged(QWidget * old, QWidget * now)