【发布时间】:2010-07-26 05:41:38
【问题描述】:
我想在 Qt 中自定义一个列表视图,谁能给我一些示例或提示如何做到这一点?我是 Qt 新手。
【问题讨论】:
标签: qt listview qt4 custom-controls symbian
我想在 Qt 中自定义一个列表视图,谁能给我一些示例或提示如何做到这一点?我是 Qt 新手。
【问题讨论】:
标签: qt listview qt4 custom-controls symbian
您可以将样式表应用到您的QListView。
查看 here 以获取使用样式表自定义 QListView 的 Qt 文档。
【讨论】:
如果您使用标准项目模型或 QListWidget(或任何其他使用 QStandardItem 的模型),则可以使用 setData 设置项目的外观属性。
因此,以下将向列表小部件添加一个红色项目:
QListWidgetItem *colorItem = new QListWidgetItem("Red");
colorItem->setData(QBrush(QColor(Qt::red)), Qt::ForegroundRole);
list.addItem(colorItem);
工作代码示例和更详细的解释请见:http://ynonperek.com/qt-mvc-customize-items
【讨论】: