Qt:选择项目时如何显示图标

发布于 2024-08-19 15:42:43 字数 102 浏览 5 评论 0原文

我有一个 QListWidget,其中包含带有图标的项目,当选择这些项目时,图标会突出显示。有办法防止这种情况吗?我无法使用样式表,因为它用于嵌入式应用程序并且包含它们会占用太多空间。 谢谢

I have a QListWidget containing items which have icons and when the items are selected the icon is just highlighted out. Is there a way to prevent this? I can't use stylesheets because it's for an embedded application and including them takes up too much space.
thanks

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

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

发布评论

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

评论(2

来日方长 2024-08-26 15:42:43

我想当你说“Highlithed out”时,你的意思是当选择该行时图标颜色渲染得不好,因此,你无法正确看到图标......

也许你可以考虑使用不同的图标该项目被选中。可以通过为图标指定模式来实现此目的。

示例:

QIcon MyIcon(":/images/foo");
MyIcon.addFile(":/images/bar", QSize(...), QIcon::Selected);

您可以轻松地在 QtDesigner 中进行尝试并查看结果...

希望它有所帮助!

I suppose when you say "Highlithed out", you mean that the icon colors don't render well when the line is selected, and therefore, you can't see properly the icon...

Maybe you could consider using a different icon when the item is selected. It's possible to do so by specifing a mode to your icon.

Example :

QIcon MyIcon(":/images/foo");
MyIcon.addFile(":/images/bar", QSize(...), QIcon::Selected);

You can easily make a try in QtDesigner and see the results...

Hope it helps a bit !

十年九夏 2024-08-26 15:42:43

当然,在黑白屏幕上绘图存在一定的挑战。

听起来您只想更改界面的外观,而不是任何功能。如果是这种情况,则 QItemDelegate-派生类(或 QStyledItemDelegate)几乎可以肯定你想要什么。特别是,drawDecoration函数看起来是用来绘制图标的,样式选项应该包括是否选中。最简单的修复方法是覆盖该函数,将选项中的选定标志设置为 false,然后将其传递给父函数。

Certainly, drawing on a black-and-white screen presents its challenges.

It sounds like you just want to change the appearance of the interface, not any functionality. If this is the case, a QItemDelegate-derived class (or QStyledItemDelegate) is almost certainly what you want. In particular, the drawDecoration function looks like it is used to draw an icon, and the style options should include whether it is selected. The simplest fix would be to override that function, set the selected flag in the options to false, then pass it up to the parent's function.

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