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. Hide entry of QComboBox/QAbstractItemView/QListView

Hide entry of QComboBox/QAbstractItemView/QListView

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 613 Views 2 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.
  • l3u_L Offline
    l3u_L Offline
    l3u_
    wrote on last edited by
    #1

    Hi :-)

    I want to force the user to select an item of a QComboBox. So I added a "dummy" item as the first one, with -1 as data set. All "normal" item have data > 0. I check the selected data, and if it's still -1, nothing was selected yet.

    I subclassed the QComboBox, and first tried to make the dummy item not selectable, which is no problem. But it shows up in the popup. Although not being selectable, I'd rather like not to see it at all.

    Then I added a showPopup() override function. I checked if the first item has data -1 there, and if so, I deleted it. That made the dummy item vanish, but also caused the QComboBox to select the next one automatically.

    That doesn't look very good either – I would like to hide the dummy item in the popup. That seems to be quite hard … is this possible?

    Thanks for all help!

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      Did you also try to set selected to -1 after you delete it in
      showPopup ?

      l3u_L 2 Replies Last reply
      0
      • mrjjM mrjj

        Hi
        Did you also try to set selected to -1 after you delete it in
        showPopup ?

        l3u_L Offline
        l3u_L Offline
        l3u_
        wrote on last edited by l3u_
        #3

        @mrjj I tried this, but it makes the selected dummy entry disappear (nothing is selected) and also triggers a selection change. Simply not seeing that one item in the popup would be nice …

        1 Reply Last reply
        0
        • l3u_L Offline
          l3u_L Offline
          l3u_
          wrote on last edited by
          #4
          This post is deleted!
          1 Reply Last reply
          0
          • mrjjM mrjj

            Hi
            Did you also try to set selected to -1 after you delete it in
            showPopup ?

            l3u_L Offline
            l3u_L Offline
            l3u_
            wrote on last edited by l3u_
            #5

            @mrjj I found a (surprisingly simple) solution (inside my QComboBox subclass):

            addItem(tr("–"), -1);
            qobject_cast<QListView *>(view())->setRowHidden(0, true);
            ...
            // Add other items
            

            The first item (my dummy item) is selected and shown as the default one, but the popup doesn't show it. Here we are :-)

            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