Get a notification/event/signal when a Qt widget gets focus

Get a notification/event/signal when a Qt widget gets focus

Asked on January 8, 2019 in Qt.
Add Comment


  • 3 Answer(s)

    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;
    }
    
    Answered on January 8, 2019.
    Add Comment

    The level of WYSIWYG programe is:

    In C++,

    class LineEdit : public QLineEdit
    {
        virtual void focusInEvent( QFocusEvent* )
        {}
    };
    
    Answered on January 8, 2019.
    Add Comment

    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)
    

     

    Answered on January 8, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.