Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QComboBox with QCompleter: multiple FocusIn event Issue
Forum Updated to NodeBB v4.3 + New Features

QComboBox with QCompleter: multiple FocusIn event Issue

Scheduled Pinned Locked Moved Unsolved General and Desktop
qcomboboxqwidgetfocus issue
1 Posts 1 Posters 594 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Zee_07Z Offline
    Zee_07Z Offline
    Zee_07
    wrote on last edited by
    #1

    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.

    Thanks and Kind Regards,
    Zee_07

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved