Results 1 to 8 of 8

Thread: Adding items to QComboBox

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,321
    Thanks
    316
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Adding items to QComboBox

    I can open it by calling showPopup()
    showPopup() is probably a nonmodal dialog-type method; that is, the popup widget contains its own event loop to monitor user selections and while it is visible it doesn't respond to changes in the combo box contents. If you want to change this behavior, you may be able to derive from QComboBox and override showPopup() . I don't think it will be very easy to do that and maintain the same behavior that the combobox popup normally has. Its implementation probably depends on there being a fixed number of items in the list, so if you are modifying the list while the user is trying to make a selection, then the indexing has to be carefully managed to avoid returning the wrong index values when a selection is made.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  2. #2
    Join Date
    Jan 2020
    Posts
    53
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Adding items to QComboBox

    It is strange that QComboBox doesn't implement this behaviour, as it would be very useful. Perhaps it will be included in Qt 6?

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,321
    Thanks
    316
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Adding items to QComboBox

    It is strange that QComboBox doesn't implement this behaviour
    I think the behaviour you propose is strange.

    The purpose of the popup is to allow the user to make a selection from the items in the combobox's list, not to display the list of items in a dynamic way. How is the user supposed to make a choice when the list she is seeing is constantly changing underneath her mouse? This would be even worse if the combobox had sorted contents - the contents would keep rearranging themselves, making it impossible to choose the one you want. More often than not, you would probably end up with the wrong one because the list changed underneath you and you didn't notice.

    And think how frustrating it would be if each time you opened the popup box, you saw a different list of items. It would be one thing if -you- did something which caused the list to change (like choose a different search term) versus the list changing because the program did it without any input from you.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  4. #4
    Join Date
    Jan 2020
    Posts
    53
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Adding items to QComboBox

    Maybe I did not explain properly what I meant. What I am after is behaviour somewhat similar to that of Wikipedia, where the list opens up as soon as one starts to type text (the lineedit under the cursor do not change) and then the selection in the drop down list is dynamically altered as one types. What's in the list will of cause have be inserted from code. That saves the user from having to manually open the drop-list.

  5. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,321
    Thanks
    316
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Adding items to QComboBox

    Ah, then what you want is not a plain QComboBox, but a QComboBox or QLineEdit containing a QCompleter in PopupCompletion mode.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. QComboBox extremely slow on adding a lot of items
    By Buldozer in forum Qt Programming
    Replies: 3
    Last Post: 16th May 2021, 12:46
  2. QComboBox with a tree model - adding items problem.
    By high_flyer in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2017, 10:33
  3. Replies: 1
    Last Post: 20th June 2013, 06:24
  4. QcomboBox items
    By therealjag in forum Newbie
    Replies: 5
    Last Post: 27th March 2006, 08:21
  5. [QT3] QComboBox: Disable adding items on Enter-keypress
    By BrainB0ne in forum Qt Programming
    Replies: 7
    Last Post: 14th January 2006, 19:43

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.