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

[REG 5.15->6.7.2] QTableView with stylesheet - indicators overlap text

    XMLWordPrintable

Details

    • All
    • f414c490d (dev)

    Description

      We had to port code to Qt6, and one of the things that broke was theĀ QTableView.

      • In Qt 5,15 and earlier, applying a style sheet with custom checkbox indicators worked fine.
      • In Qt 6.5.3, the custom image indicators overlapped over the default checkboxes and item text.
      • In Qt 6.6.3 and 6.7.2, the custom image indicators show fine, the default indicators no longer show, but the indicators are still overlapping the text.

      Simple example to reproduce:

      main.cpp

      #include "mymodel.h"
      #include <QApplication>
      #include <QTableView>
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
          QTableView tableView;
          MyModel myModel;
          tableView.setModel(&myModel);
      
          QString viewStyle = "QTableView::item { padding: 10px; }\n"
                              "QTableView::indicator { width: 30px; height: 30px; }\n"
                              "QTableView::indicator:unchecked { image: url(:/checkbox_unselected.png); }\n"
                              "QTableView::indicator:checked { image: url(:/checkbox_selected.png); } ";
          tableView.setStyleSheet(viewStyle);
          tableView.setColumnWidth(0, 100);
          tableView.setColumnWidth(1, 100);
          tableView.setColumnWidth(2, 100);
          tableView.setRowHeight(0, 100);
          tableView.setRowHeight(1, 100);
      
          tableView.show();
          return a.exec();
      }

      mymodel.h:

      #include <QAbstractTableModel>
      
      class MyModel : public QAbstractTableModel
      {
      public:
          explicit MyModel(QObject *parent = nullptr);
          int rowCount(const QModelIndex &parent = QModelIndex()) const override;
          int columnCount(const QModelIndex &parent = QModelIndex()) const override;
          QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
      }; 

      mymodel.cpp:

      #include "mymodel.h"
      
      MyModel::MyModel(QObject *parent) : QAbstractTableModel(parent)  { }
      
      int MyModel::rowCount(const QModelIndex & /*parent*/) const
      {
          return 2;
      }
      
      int MyModel::columnCount(const QModelIndex & /*parent*/) const
      {
          return 3;
      }
      
      QVariant MyModel::data(const QModelIndex &index, int role) const
      {
          if (role == Qt::DisplayRole) {
              return QString("Row%1, Column%2").arg(index.row() + 1).arg(index.column() +1);
          }
          else if (role == Qt::CheckStateRole) {
              return (index.column() == 0) ? Qt::Checked : Qt::Unchecked;
          }
          return QVariant();
      } 

      Attachments

        1. all.png
          all.png
          72 kB
        2. QTBUG-129290.7z
          4 kB
        For Gerrit Dashboard: QTBUG-129290
        # Subject Branch Project Status CR V

        Activity

          People

            chehrlic Christian Ehrlicher
            Thalia Mihaela Gaspar
            Votes:
            2 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes