user316416
user316416

Reputation: 51

How to customize a listview in Qt

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

Answers (2)

liaK
liaK

Reputation: 11648

You can apply stylesheet to your QListView.

Check out here for the Qt documentation of customizing QListView using stylesheets.

Upvotes: 4

Ynon
Ynon

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

Related Questions