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 model: Can't select from list
Qt 6.11 is out! See what's new in the release blog

QCombobox with model: Can't select from list

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 3.5k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    I am seeing some weird behavior from my QCombobox, and I'm hoping someone can help me understand what is going on.

    I've got a dialog that has a QCombobox in it. I am using a QAbstractListModel and QSortFilterProxyModel to populate the QCombobox's list view. This all seems to be working.

    Initially the list is empty. If type a new entry into the QCombobox and click on my 'OK' button, the CurrentIndex is set to -1 (which I expect), and I add the new entry to my data source. This all seems to be working.

    If I open my dialog again (now there is one item in the list), I can click on the drop-down arrow on the QCombobox, and I will see the new entry in the list, but I cannot select it. Even if I don't view the list, if I type a new entry into the QCombobox and click 'OK', I find the CurrentIndex is set to 0.

    What am I doing wrong?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      Could you verify that the model behaves as expected outside of the contect of a QComboBox? Preferably by using the ModelTest tool, but if needed by just putting it in a list view?

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        I added a list view, and it looks correct. I also noticed that if I don't try to select from the combobox's list, my currentIndex stays at -1 like it should.

        If I try to select from the list, the currentIndex is updated correctly, but the selected item is not displayed by the combobox.

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          In the virtual function data() , when the role == Item::EditRole | Item::DisplayRole, valid data should be returned.

          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