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 lineEdit value not inserted in selection list
QtWS25 Last Chance

QComboBox lineEdit value not inserted in selection list

Scheduled Pinned Locked Moved Solved General and Desktop
extend selectioselection listqcombobox
2 Posts 2 Posters 971 Views
  • 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.
  • K Offline
    K Offline
    koahnig
    wrote on last edited by
    #1

    The behaviour of an editable QComboBox allows the change of the selection list. However, the selction list is only changed when the new value has been typed and at the end the return/enter key is pressed.

    When typing a vlaue and changing the focus with <tab>, or most likely also with others methods, the value remains in the line edit, but is not entered in the selection list.

    This has a couple of disadvantages e.g. when application shall learn/extend the selection lists.

    How can I convince QComboBox to add also entries to selection list as soon as the input widget is loosing focus?

    Vote the answer(s) that helped you to solve your issue(s)

    raven-worxR 1 Reply Last reply
    0
    • K koahnig

      The behaviour of an editable QComboBox allows the change of the selection list. However, the selction list is only changed when the new value has been typed and at the end the return/enter key is pressed.

      When typing a vlaue and changing the focus with <tab>, or most likely also with others methods, the value remains in the line edit, but is not entered in the selection list.

      This has a couple of disadvantages e.g. when application shall learn/extend the selection lists.

      How can I convince QComboBox to add also entries to selection list as soon as the input widget is loosing focus?

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

      @koahnig

      Not directly. You have to fake it:

      bool eventFilter(QObject* watched, QEvent* event)
      {
          if( watched == comboBox )  // or watched->inherits("QComboBox") ??
          {
                // you may want to do additional checks here for a generic solution (like the combobox is really editable, it has a insert policy set, etc)
                switch( event->type() )
                {
                     case QEvent::FocusOut:
                     {
                              QKeyEvent keyEvent( QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier );
                              QCoreApplication::instance()->sendEvent( watched, &keyEvent );
                     }
                     break;
                }
          }
      
          return BaseClass::eventFilter(watched,event);
      }
      

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      2

      • Login

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