Reputation: 2967
The Delegate system is not clear to me by now.
I have a QListView properly displaying my custom model.
My model is composed by the following columns:
Column 1, 2 and 3 are a Text column, the column's item's text is filled using QAbstractItem::setText();
Column 4, 5, 6 and 7 are a QVariant of a custom class. These column have items filled with QAbstractItem::setData(QVariant::fromValue(MyCustomClass());
What I need from the QListView is it to display the text on the column 1,2 and 3, and display a custom QString obtained by a method of MyCustomClass on clumns 4,5,6 and 7.
How can I achieve that?
Upvotes: 1
Views: 864
Reputation: 22356
Use QAbstractItemView::setItemDelegateForColumn(int column, QAbstractItemDelegate* delegate)
, docs.
Have you got a custom model? If all you are pulling out of your custom data is text, it would be easier to reimplement QAbstractItemModel::data(const QModelIndex& index, int role) const
, query which column index
is, and if it is your custom data column return the display role with the custom data text; otherwise just call the parent implementation.
Upvotes: 3