Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Hide QCombobox item correctly and not ruin the view

    General and Desktop
    qcombobox qlistview
    2
    5
    399
    Loading More Posts
    • 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
      johnyang last edited by johnyang

      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 Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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 Reply Quote 0
        • J
          johnyang last edited by johnyang

          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 Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            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 Reply Quote 0
            • J
              johnyang @SGaist last edited by

              @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 Reply Quote 0
              • First post
                Last post