How to display icons in QTableView via a custom QAbstractItemModel?
c++, model, qt
Solution
`Qt::DisplayRole` is only for text. Add:
if ( role == Qt::DecorationRole ) {
return iconProvider->icon(QFileIconProvider::Folder);
}
Problem
I'm building a custom QAbstractItemModel model. The first column contains icons, the second one - text. This is the code of the data method: ``` QVariant data ( const QModelIndex & index, int role = Qt::DisplayRole ) const { if(role != Qt::DisplayRole ) return QVariant(); int col = index.column(); if (col == 0) { return iconProvider->icon(QFileIconProvider::Folder); } else if (col == 1) { return "TEXT"; } } ``` But all I get in the resulting Table View is just text in the second column. There's no folder icon in the first column. Am I missing something here?