I have tried stylesheet, html format and palette to change the color of radio button to white but they did not work.
is there a way to change it ? in the documantation of QRadioButton there is no function for text color.
I have tried stylesheet, html format and palette to change the color of radio button to white but they did not work.
is there a way to change it ? in the documantation of QRadioButton there is no function for text color.
If you want to change the foreground color only of Radio button you may need to provide alpha background color for that button. for example:
QRadioButton{ color: rgb(255, 255, 255); background-color: rgba(255, 255, 255, 0);}
This will give you white color with transparent background.
That sound strange. Both with QtCreator and QtDesigner setting the stylesheet
property of the QRadioButton to
color: white; background-color: red;
give you a QRadioButton with a white text on a red background (if I understand the question)
You will need to subclass QProxyStyle
and reimplement the drawControl()
method to catch calls with QStyle::CE_RadioButton
.
If you look at the source for QRadioButton::paintEvent()
:
QStylePainter p(this);
QStyleOptionButton opt;
initStyleOption(&opt);
p.drawControl(QStyle::CE_RadioButton, opt);
initStyleOption()
does not do anything but set state data; everything is handled by the painter. Here's QStylePainter::drawControl()
, which simply calls the current QStyle to do the job:
void QStylePainter::drawControl(QStyle::ControlElement ce, const QStyleOption &opt)
{
wstyle->drawControl(ce, &opt, this, widget);
}
The Qt docs include information on how to subclass and load a proxy style: http://doc.qt.io/qt-5/qproxystyle.html. Peek into the QCommonStyle::drawControl()
implementation to see how Qt goes about painting the control.