您的位置:首页 > 编程语言 > Qt开发

QT自定义控件重叠颜色异常

2016-07-27 12:17 459 查看
首先看错误效果



这是两个QListWidget的item

QListWidget 设置了alternatingRowColors(item 交替变换颜色)

item是我自定义的widget控件,上面放了一些QLabel,其中文本QLabel我使用QPalette设置为灰色,但始终显示黑色。

下面是修正效果图



原因:先看QT Assistant 对于alternatingRowColors属性的解释

If this property is true, the item background will be drawn usingQPalette::Base
andQPalette::AlternateBase; otherwise the background will be drawn using theQPalette::Base
color.

所以我认为item的QPalette也被改变,通过setBackgroundRole(QPalette::Text);即可是文本正确显示
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: