I’m displaying a model in a QTreeView. The data displayed consists of text. The behaviour I’m trying to achieve is to show only a single line of text in rows that are not selected and all lines (whether there is one or many) in the selected rows.
I was considering reimplementing QStyledItemDelegate’s displayText method but the only information it provides are the data and locale. I need access to the view’s QItemSelectionModel or something to determine if the currently requested text is in a selected row or not. Any ideas?
Reimplement
QStyledItemDelegate::createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index ). The “parent” controls how the data is represented. You can create you own widget and display whatever you want there. Unfortunately item delegates do not provide access to the view, so you can create a reference to your view in the delegate.