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 QCombobox item correctly and not ruin the view
QtWS25 Last Chance

Hide QCombobox item correctly and not ruin the view

Scheduled Pinned Locked Moved Unsolved General and Desktop
qcomboboxqlistview
5 Posts 2 Posters 2.0k 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.
  • J Offline
    J Offline
    johnyang
    wrote on last edited by johnyang
    #1

    There is a solution to use setRowHidden function from QListView like:
    qobject_cast<QListView *>(combobox->view())->setRowHidden(0, true);

    This certainly does the job, but I found an issue with this solution. A combobox normally will automatically adjust its pop-up view downwards/upwards based on its visibility. However, once the setRowHidden is called, it will no longer do that. It becomes a small dropdown list with scrollbar showing only two items at a time.

    How to fix this? Or is the default combobox view is not simply a QListView?

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

      Hi,

      Which version of Qt is it ?
      On which platform ?
      Can you provide a minimal compilable example that shows this behaviour ?

      Did you try to use QSortFilterProxyModel between the QComboBox view and model ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • J Offline
        J Offline
        johnyang
        wrote on last edited by johnyang
        #3

        I'm with Qt5.14.2 in Windows. The "fusion" style in Linux won't have this issue but it has the same issue with both Windows and Windows Vista style.
        An simple example is like following:

        auto combobox = new QCombobox(this);
        combobox->addItem("1min");
        combobox->addItem("2mins");
        combobox->addItem("3mins");
        ...
        combobox->addItem("All");
        qobject_cast<QListView *>(combobox->view())->setRowHidden(0, true);
        qobject_cast<QListView *>(combobox->view())->setRowHidden(1, true);
        qobject_cast<QListView *>(combobox->view())->setRowHidden(2, true);
        

        Then the combobox won't auto-adjust anymore to go upwards nor showing more contents as the normal combobox would. See below:
        combobox_notworking.png
        If I remove those lines with setRowHidden(), it will work as usual. See below:
        combobox_working.png
        I felt this function somehow changes some settings in the backend of the combobox implementation or the view behaviour.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          And if you force the fusion style on Windows ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          J 1 Reply Last reply
          0
          • SGaistS SGaist

            And if you force the fusion style on Windows ?

            J Offline
            J Offline
            johnyang
            wrote on last edited by
            #5

            @SGaist If forcing fusion style, it'll show the full list. But the style itself is very different. Fusion style has tick boxes and shows everything with no scrollbar I think.

            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