Felipe Lavratti
Felipe Lavratti

Reputation: 2967

Qt QListView with different delegates per column

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:

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

Answers (1)

cmannett85
cmannett85

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

Related Questions