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

QAbstractItemView::indicator not working properly

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2: Important P2: Important
    • 6.5.5-1, 6.6.3, 6.8.0 FF
    • 6.3.2, 6.4.0, 6.5.2, 6.6.2
    • Widgets: Itemviews
    • None
    • Windows10 + Qt
    • Windows
    • 1ac58f4ba (dev), da59bc343 (6.7), 347b35a44 (6.6), 3bc823495 (tqtc/lts-6.5)

      Hello!
      When I create a view/model and display the view's CheckBox, I only need to set the Qss about QAbstractItemView::indicator, such as QAbstractItemView::indicator { width: 6px; height: 6px; border: 1px solid black;}
      Then the display of the View is messed up at this time, and it looks like the original CheckBox and Styled CheckBox are drawn together.
      But this demo runs normally on Qt5.15.2. You can use the following simple Demo to reproduce:

      #include <QtWidgets>
      
      class TestModel : public QAbstractListModel
      {
          Q_OBJECT
      public:
          explicit TestModel(const QList<QString>& vals, QObject *parent = nullptr) : QAbstractListModel(parent), vals_{vals}{}
      
          int rowCount(const QModelIndex &parent = QModelIndex()) const {
              Q_UNUSED(parent)
              return vals_.size();
          }
          QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const {
              if (!index.isValid())
                  return QVariant();
      
              switch(role) {
              case Qt::DisplayRole:
                  return vals_.at(index.row());
              case Qt::CheckStateRole:
                  return Qt::Unchecked;
              default:
                  break;
              }
              return QVariant();
          }
      
      private:
          QList<QString> vals_;
      };
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
      
          QListView view;
          view.setWindowTitle(qVersion());
          view.setModel(new TestModel(QList<QString>{QStringLiteral("11111"), QStringLiteral("22222"), QStringLiteral("33333")}, &view));
          view.setStyleSheet(QStringLiteral("QAbstractItemView::indicator { width: 6px; height: 6px; border: 1px solid black;}"));
          view.show();
      
          return a.exec();
      }
      
      #include "main.moc"
      

      Thanks

        1. 6.6.2.png
          6.6.2.png
          4 kB
        2. 6.5.2.png
          6.5.2.png
          4 kB
        3. 6.4.0.png
          6.4.0.png
          4 kB
        4. 6.3.2.png
          6.3.2.png
          4 kB
        5. 5.15.2.png
          5.15.2.png
          4 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            pupu5642 yaxin zhao
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes