Reputation: 51
I want to customize a listview in Qt, can anyone provide me some example or hints of how to do it? I am new to Qt.
Upvotes: 5
Views: 5219
Reputation: 11648
You can apply stylesheet to your QListView
.
Check out here for the Qt documentation of customizing QListView
using stylesheets.
Upvotes: 4
Reputation: 21
If you're using a standard item model or a QListWidget (or any other model that uses QStandardItem), you can set appearance properties on the items using setData.
So, The following will add a red item to a list widget:
QListWidgetItem *colorItem = new QListWidgetItem("Red");
colorItem->setData(QBrush(QColor(Qt::red)), Qt::ForegroundRole);
list.addItem(colorItem);
For a working code example and more detailed explanation, please see: http://ynonperek.com/qt-mvc-customize-items
Upvotes: 2