Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-120574

QComboBox popup high decreases when hiding view items

    XMLWordPrintable

Details

    • All
    • 742be5254 (dev), 8e6b46fa6 (6.7), ed68a6ba4 (6.6)

    Description

      When the QApplication style is set to "Windows", hiding view-items of the QCombobox decreases the popup high and the number of items shown.

      #include "qstyle.h"
      
      #include <QApplication>
      #include <QHBoxLayout>
      #include <QListView>
      #include <QMainWindow>
      #include <qcombobox.h>
      
      class MainWindow : public QMainWindow {
      
      private:
          QComboBox *comboBox;
      public:
          MainWindow(QWidget *parent = nullptr) : QMainWindow(parent) {
              QHBoxLayout *mainLayout = new QHBoxLayout;
              QWidget *mainWidget = new QWidget(parent);
      
              QComboBox *comboBox = new QComboBox;
      
              comboBox->addItem("Item 1");
              comboBox->addItem("Item 2");
              comboBox->addItem("Item 3");
              comboBox->addItem("Item 4");
              comboBox->addItem("Item 5");
              comboBox->addItem("Item 6");
              comboBox->addItem("Item 7");
              comboBox->addItem("Item 8");
              comboBox->addItem("Item 9");
              comboBox->addItem("Item 10");
              comboBox->addItem("Item 11");
              comboBox->addItem("Item 12");
              comboBox->addItem("Item 13");
              comboBox->addItem("Item 14");
              comboBox->addItem("Item 15");
              comboBox->addItem("Item 16");
              comboBox->addItem("Item 17");
              comboBox->addItem("Item 18");
      
              // number of visible items is less the comboBox->maxVisibleItems()
              QListView *view = qobject_cast<QListView *>(comboBox->view());
              view->setRowHidden(1, true);
              view->setRowHidden(2, true);
              view->setRowHidden(3, true);
              view->setRowHidden(4, true);
              view->setRowHidden(5, true);
              view->setRowHidden(6, true);
              view->setRowHidden(7, true);
      
              mainLayout->addWidget(comboBox);
              mainWidget->setLayout(mainLayout);
      
              setCentralWidget(mainWidget);
          };
      };
      
      int main(int argc, char *argv[]) {
      
          QApplication a(argc, argv);
          a.setStyle("Windows"); // bug requires Windows style
          qInfo("%s", a.style()->metaObject()->className());
          MainWindow w;
          w.show();
          return a.exec();
      }
      

      This issue might be similar https://bugreports.qt.io/browse/QTBUG-38251

      I think the problem might be that the item counter approaching maxVisibleItems doesn't check if the modelIndex is visibleĀ  https://github.com/qt/qtbase/blob/c4bd6ac4e5a0782d8771af1485a3b78733180785/src/widgets/widgets/qcombobox.cpp#L2660C1-L2680C40

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            chehrlic Christian Ehrlicher
            anthony12356 Anthony Kersten
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There is 1 open Gerrit change