QComboBox with QCompleter: multiple FocusIn event Issue



  • Whenever popUp of editable QComboBox gets closes (no match found in popUp view) FocusIn event gets triggered in eventfilter. Below id my code snippet:
    class

    MyComboBox::MyComboBox(QWidget *parent):QComboBox(parent)
    {
        installEventFilter(this);
    }
    
    bool MyComboBox::eventFilter(QObject *target, QEvent *event)
    {
        if (target == this)
        {
            if(event->type() == QEvent::FocusOut) {
                            qDebug()<<"22 Focus OUT event ::"<<this;
    
            }
            else if(event->type() == QEvent::FocusIn) {
                            qDebug()<<"11 Focus IN event ::"<<this;
            }
        }
        return QWidget::eventFilter(target,event);
    }
    

    in MainWindow where I am instantiating it:

    MyComboBox *combo = new MyComboBox(this);
        combo->setEditable(true);
        QCompleter *completer1 = new QCompleter(this);
        completer1->setCompletionMode(QCompleter::PopupCompletion);
    
        for (int var = 1; var < 100; ++var) {
            combo->addItem(QString("%1").arg(var*7));
        }
        completer1->setModel(combo->model());
        combo->setCompleter(completer1);
    

    My requirement is if user first entered into MyComboBox (either by click or by tabFocus change) he can directly start writing text in lineedit and QCompleter popup will get shown. So I write this functionality in foucsIn event lineEdit()->selectAll();
    But issue is if lineedit text doesn't matched to any text in poupup view, then popUp view gets closed and again FocusIn event gets called and select all text inside lineedit.