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

QListView reports wrong contentsMargins with Vista style

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 4.8.7, 5.6.3, 5.9.9, 5.12.7, 5.14.1
    • None
    • Windows

    Description

      #include <QApplication>
      #include <QListView>
      #include <QStringListModel>
      
      class ListView : public QListView
      {
      public:
        explicit ListView(QWidget *parent = nullptr)
        : QListView(parent)
        {
          setUniformItemSizes(true);
        }
      
        QSize sizeHint() const override
        {
          QMargins margins = contentsMargins();
          return { QListView::sizeHint().width(),
                   margins.top() +
                   10 * rectForIndex(indexAt(QPoint(0, 0))).height() +
                   margins.bottom() };
        }
      };
      
      int main(int argc, char **argv)
      {
        QApplication app(argc, argv);
      
        QStringListModel model({"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"});
      
        ListView view;
        view.setModel(&model);
        view.show();
      
        return QApplication::exec();
      }

      It is expected that the list view will have exactly the required height for 10 items (similar implementations of sizeHint() work for QTreeView and QTableView), but it shows up being a bit shorter.
      QListView has a special handling of the frame width in qwindowsxpstyle.cpp so it calls QFramePrivate::updateStyledFrameWidths in its constructor. This function updates *FrameWidth values but doesn't update contentsMargins unlike QFramePrivate::updateFrameWidth used by QFrame itself.
      The latter function has suggested a workaround — call setFrameRect({}) after the QListView constructor.

      Attachments

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

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            a.khlyustov a.khlyustov
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes