Details
-
Bug
-
Resolution: Fixed
-
P2: Important
-
6.5.3, 6.6.3, 6.7.2
-
None
-
-
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(); }