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 autocomplete automatically changes edittext.
Forum Update on Monday, May 27th 2025

QComboBox autocomplete automatically changes edittext.

Scheduled Pinned Locked Moved General and Desktop
13 Posts 5 Posters 14.3k 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.
  • C Offline
    C Offline
    concentricpuddle
    wrote on last edited by
    #3

    I tried using the completer with my own model from scratch and
    using QStringListModel. Getting case-insensitive completions using both methods worked fine, but the combo box would still change it's edit text if it differed in case from any preexisting item upon losing focus.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      GordonSchumacher
      wrote on last edited by
      #4

      I mean - obvious question, but did you explicitly set case-sensitive on the QCompleter?

      1 Reply Last reply
      0
      • C Offline
        C Offline
        concentricpuddle
        wrote on last edited by
        #5

        Yes, then the problem is resolved. But then autocompletion becomes almost useless as the I'd have to remember the original string as opposed to changing the case of various words as I type since no completion is suggested.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          GordonSchumacher
          wrote on last edited by
          #6

          Let me be sure I understand, then... what you want is that the user starts typing, and items are suggested in a case-insensitive manner - but the completion does not happen unless the user explicitly selects it?

          (For what it's worth, I don't think that this has anything to do with case-sensitivity - if you do as we discussed above and you do type in the "right" case, does it still auto-select it?)

          1 Reply Last reply
          0
          • C Offline
            C Offline
            concentricpuddle
            wrote on last edited by
            #7

            ...yes. Say there're the following items in the Combo Box. 'first item', 'second item' and 'third item'

            Assume to completer is set to case-insensitive.

            1. Now if the user started typing 'first', 'first item' will be the suggested completion and ' item' will then be highlighted. I can press Enter to accept the completion and the combo box's text will become 'first item'.

            2. If I'd started typing 'First', 'first item' would still be the suggested and completion, but the edit text will be 'First item' where ' item' will be highlighed. If I press Enter to accept the autocompletion, the text will change to 'first item'. While I'd like the text to be 'First item', I can live with this.

            3. If I type in 'First Item' then change the focus to anything else (like clicking on another window) the text will become 'first item'. This is NOT what I want. I'd like the text to stay at 'First Item' unless explicitly changed by me.

            This is the way things were with Qt < 4.5.

            If the completer were set to case-sensitive the combo box doesn't change the text as in 3, but no completions are suggested either. Completions for 2 are suggested, but this operation is rarely required in my app whereas 3 is done quite a bit.

            1 Reply Last reply
            0
            • B Offline
              B Offline
              baysmith
              wrote on last edited by
              #8

              Can you filter the focus out event to prevent the completer from activating?

              Nokia Certified Qt Specialist.

              1 Reply Last reply
              0
              • C Offline
                C Offline
                concentricpuddle
                wrote on last edited by
                #9

                Nope. If I don't run it at all, I get artifacts like the caret still being visible on the combo box even if the focus is on another combo box (I have more than one in my app, but this behaviour is manifested if I change the focus to any widget).

                Edit: Just realized what you meant. Checking it now.

                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  concentricpuddle
                  wrote on last edited by
                  #10

                  No luck. I get artifacts like the combo box seeming to have focus when it doesn't, like the caret still being visible and the selection not being discarded after pressing tab.

                  Here's the code I used:

                  @def eventFilter(self, obj, event):
                  if isinstance(obj, QComboBox) and event.type() == QEvent.FocusOut:
                  return True
                  return QGroupBox.eventFilter(self, obj, event) #The combo box has a QGroupBox parent
                  @
                  In C++ it'd be (I think):

                  @bool ComboGroup::eventFilter(QObject *obj, QEvent *event)
                  {
                  if (obj.inherits("QComboBox")
                  {
                  if (event->type() == QEvent::FocusOut)
                  return true;
                  }
                  else
                  {
                  return QGroupBox::eventFilter(obj, event);
                  }
                  }@

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    GordonSchumacher
                    wrote on last edited by
                    #11

                    Okay, I would post a "bug report":http://bugreports.qt.nokia.com on this one then; I don't know whether that was an intentional change or not.

                    1 Reply Last reply
                    0
                    • manikandanM Offline
                      manikandanM Offline
                      manikandan
                      wrote on last edited by
                      #12

                      Is this bug fixed now? am seeing this issue even in Qt5.5.1

                      aha_1980A 1 Reply Last reply
                      0
                      • manikandanM manikandan

                        Is this bug fixed now? am seeing this issue even in Qt5.5.1

                        aha_1980A Offline
                        aha_1980A Offline
                        aha_1980
                        Lifetime Qt Champion
                        wrote on last edited by
                        #13

                        @manikandan said in QComboBox autocomplete automatically changes edittext.:

                        Is this bug fixed now? am seeing this issue even in Qt5.5.1

                        Well it seems the bug was never reported and therefore it cannot be fixed :(

                        Qt has to stay free or it will die.

                        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