2

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.

irukeru
  • 509
  • 1
  • 10
  • 26

3 Answers3

2

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.

Sherry
  • 21
  • 4
1

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)

Gianluca
  • 3,227
  • 2
  • 34
  • 35
1

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.

jonspaceharper
  • 4,207
  • 2
  • 22
  • 42