Problem with QStyledItemDelegate and QSortFilterProxyModel
-
I have a table model based on a QAbstractTableModel.
I use a subclass of QStyledItemDelegate to handle display of one of the columns
Up until now I didn't have sort capability, so I interposed a QSortFilterProxyModel
between the table model and the table view:// // Set up a QSortFilterProxyModel to allow sorting of the table view // (it sits between the actual model and the view to provide sorting // capabilty) // proxyModel = std::make_unique<QSortFilterProxyModel>(this); proxyModel->setSourceModel(frameList.currentTableModel()); ui->tableView->setModel(proxyModel.get()); ui->tableView->setSortingEnabled(true);net result the styled item delegate blew up on the Q_ASSERT in the following code that checks the cell attributes are correct:
constexpr uint neededFeatures { static_cast<uint>(QStyleOptionViewItem::HasCheckIndicator | QStyleOptionViewItem::HasDisplay | QStyleOptionViewItem::HasDecoration) }; Q_ASSERT(neededFeatures == (opt.features & neededFeatures));Shouldn't the sort filter proxy model pass that sort of stuff through?
David
-
@Perdrix Nice to hear, can you mark the topic as solved then?
Normally a SFPM does not change the data until you derive from it and change it somewhere by your own.
-
I have a table model based on a QAbstractTableModel.
I use a subclass of QStyledItemDelegate to handle display of one of the columns
Up until now I didn't have sort capability, so I interposed a QSortFilterProxyModel
between the table model and the table view:// // Set up a QSortFilterProxyModel to allow sorting of the table view // (it sits between the actual model and the view to provide sorting // capabilty) // proxyModel = std::make_unique<QSortFilterProxyModel>(this); proxyModel->setSourceModel(frameList.currentTableModel()); ui->tableView->setModel(proxyModel.get()); ui->tableView->setSortingEnabled(true);net result the styled item delegate blew up on the Q_ASSERT in the following code that checks the cell attributes are correct:
constexpr uint neededFeatures { static_cast<uint>(QStyleOptionViewItem::HasCheckIndicator | QStyleOptionViewItem::HasDisplay | QStyleOptionViewItem::HasDecoration) }; Q_ASSERT(neededFeatures == (opt.features & neededFeatures));Shouldn't the sort filter proxy model pass that sort of stuff through?
David
@Perdrix said in Problem with QStyledItemDelegate and QSortFilterProxyModel:
Shouldn't the sort filter proxy model pass that sort of stuff through?
Yes, please show a minimal, compilable example of your code
proxyModel = std::make_unique<QSortFilterProxyModel>(this);
Happy crashings
-
@Perdrix said in Problem with QStyledItemDelegate and QSortFilterProxyModel:
Shouldn't the sort filter proxy model pass that sort of stuff through?
Yes, please show a minimal, compilable example of your code
proxyModel = std::make_unique<QSortFilterProxyModel>(this);
Happy crashings
-
@Perdrix Nice to hear, can you mark the topic as solved then?
Normally a SFPM does not change the data until you derive from it and change it somewhere by your own.