Hi All,
How to set color of the radio button to green.
device state : connected - set radio button to green color
I tried ui->radio_button->setStyleSheet("background-color: green");
Can someone help me to fix it?
Thanks,
Anita
Hi All,
How to set color of the radio button to green.
device state : connected - set radio button to green color
I tried ui->radio_button->setStyleSheet("background-color: green");
Can someone help me to fix it?
Thanks,
Anita
Widgets that are 'controls', like radio buttons, are drawn as a set of 'primitive elements'. The Primitive element for the indicator (the circle) is PE_IndicatorRadioButton. If you dig deep into the Qt style source code for the basic style, the outline is drawn using settings from the QPalette for the control.
The QPen is set using the palette's QPalette::dark() color, and this pen draws the outline of the circle.
If the radio button is on (selected, checked), the QBrush is set using the palette's QPalette::windowText() color. This fills the circle. If it is not filled, then no brush is used.
However, be aware that the QPalette::WindowText color is also used to draw the radio button's text, so if you set this palette entry to green, you'll also get green text. The only way to change this is to write your own QStyle.
So you can manipulate the QPalette directly for your radio buttons.
<=== The Great Pumpkin says ===>
Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.
Qt Code:
ui->Is_connected->setPalette(pal); ui->Is_connected->setEnabled(true);To copy to clipboard, switch view to plain text mode
I tried using above piece of code to set the Radio button color. Looks like, it's not working.
You mentioned that to manipulate the QPalette directly for the radio buttons. Could you please elaborate on it.
Best Regads,
Anita
Read the answer: WindowText, not Button. And if you are using a custom style, like Fusion or one of the others, then that style might use its own colors.If the radio button is on (selected, checked), the QBrush is set using the palette's QPalette::windowText() color.
<=== The Great Pumpkin says ===>
Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.
Hi,
Thank you for the reply.
Currently I am using below version for my development open source. As I am completely new, not aware of different styles.
Qt Creator 4.14.0
Qt 5.15.2 (MSVC 2019, 64 bit)
My requirement is Based on serial command response to the device connect request, the radio button color should be displayed in green color.
I am no where finding solution for this. Any further approach?
Thanks,
Anita
It doesn't matter what your requirement is. If you use the standard QRadioButton, you cannot change the color of the indicator to green without also changing the text color.My requirement
As I said above, the code for drawing the parts of the QRadioButton widget is very deep inside the Qt widgets implementation and cannot be customized unless you derive your own radio button and draw it yourself, you modify the QPalette::WindowText property for the button's QPalette, or you implement a custom QStyle to change the way the elements of the QRadioButton are drawn.
That's it. There is no magic solution to be found by searching. What you want to do cannot be done except through a lot of heavy work and a very good understanding of how Qt styles and widgets work together to create what you see on screen.
<=== The Great Pumpkin says ===>
Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.
Bookmarks