如何在Qt中自定义列表视图

发布于 2024-09-11 05:25:43 字数 61 浏览 1 评论 0原文

我想在 Qt 中自定义列表视图,任何人都可以为我提供一些示例或提示来说明如何做到这一点吗?我是 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

人事已非 2024-09-18 05:25:43

您可以将样式表应用到您的QListView

请查看此处获取以下 Qt 文档使用样式表自定义QListView

You can apply stylesheet to your QListView.

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

じее 2024-09-18 05:25:43

如果您使用标准项目模型或 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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文