Qt:选择项目时如何显示图标
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想当你说“Highlithed out”时,你的意思是当选择该行时图标颜色渲染得不好,因此,你无法正确看到图标......
也许你可以考虑使用不同的图标该项目被选中。可以通过为图标指定模式来实现此目的。
示例:
您可以轻松地在 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 :
You can easily make a try in QtDesigner and see the results...
Hope it helps a bit !
当然,在黑白屏幕上绘图存在一定的挑战。
听起来您只想更改界面的外观,而不是任何功能。如果是这种情况,则
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 (orQStyledItemDelegate
) is almost certainly what you want. In particular, thedrawDecoration
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.