2015-04-29 76 views
0

我已经尝试过样式表,html格式和调色板,将单选按钮的颜色更改为白色,但它们不起作用。更改Qt中的单选按钮文本颜色

有没有办法改变它?在QRadioButton的文档中没有文字颜色的功能。

回答

1

听起来很奇怪。无论用QtCreator和QtDesigner的QRadioButton的stylesheet属性设置为

color: white; background-color: red; 

给你一个QRadioButton有白色文字,红色背景 (如果我没有理解这个问题)

+0

我已经尝试过很多次了,文字的颜色没有改变。 – irukeru

+0

你可以发布一个代码示例(如果你正在尝试做这个代码)你想要什么? – Gianluca

+0

我已经重新安装了qt编译器,并解决了问题:/它太傻了,我不知道为什么会发生:( – irukeru

0

您将需要继承QProxyStyle并重新实现drawControl()方法以QStyle::CE_RadioButton来接电话。

如果你看看源QRadioButton::paintEvent()

QStylePainter p(this); 
QStyleOptionButton opt; 
initStyleOption(&opt); 
p.drawControl(QStyle::CE_RadioButton, opt); 

initStyleOption()没有做任何事情,但设置状态数据;一切都由画家处理。这里的QStylePainter::drawControl(),它只是调用当前将QStyle做的工作:

void QStylePainter::drawControl(QStyle::ControlElement ce, const QStyleOption &opt) 
{ 
    wstyle->drawControl(ce, &opt, this, widget); 
} 

Qt的文档包括如何继承并加载代理样式信息:http://doc.qt.io/qt-5/qproxystyle.html。查看QCommonStyle::drawControl()实现,了解Qt如何绘制控件。

0

如果您只想更改单选按钮的前景色,则可能需要为该按钮提供alpha背景色。例如:

QRadioButton{ color: rgb(255, 255, 255); background-color: rgba(255, 255, 255, 0);} 

这会给你透明背景的白色。