Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 485
user316416 Avatar asked Jul 26 '10 05:07

user316416


2 Answers

You can apply stylesheet to your QListView.

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

like image 168
liaK Avatar answered Oct 15 '22 02:10

liaK


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

like image 20
Ynon Avatar answered Oct 15 '22 03:10

Ynon