QComboBox下拉列表-设置选中项样式
是否可以设置QComboBox下拉列表的所选项目样式(Qt样式表)?
Is it possible to set selected item style (Qt style sheet) of the QComboBox drop-down list?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
解决方案是
方法如下:
备注:
我认为,根据 Qt 文档 应用此风格也应该有效……但事实并非如此。
The solution is to
Here is how:
Remark:
I think, according to the Qt docs applying this style should also work...but it does not.
如果您的意思是希望当组合框显示其元素时(即处于“下拉”状态),所选项目显示不同,您可以更改调色板中突出显示和突出显示文本的颜色,或设置内部
QAbstractItemView
如果您只是指处于“折叠”状态的元素的样式,我会看一下“自定义 QComboBox" Qt 样式表参考示例部分关于你正在尝试做的事情。
If you mean you want the selected item to appear different when the combo box is showing its elements (i.e. in the "dropped down" state), you can change the colors for the Highlight and HighlightedText in the palette, or style the inner
QAbstractItemView
If you just mean the style of the element in its "collapsed" state, I'd take a look at the "Customizing QComboBox" section of the Qt Style Sheets reference for examples on what you are trying to do.
@Sergey Vlasov:我不知道是否有更好的解决方案来解决您的问题,但是我设法通过以下方法解决了它:
然后在组合框中使用您的委托:
这消除了所选项目周围的讨厌框架
@Sergey Vlasov: I don't know if there is a better solution to your problem but , but I managed to solve it with the following:
And then using your delegate in your combobox:
this eliminates nasty frame around selected item