PDA

View Full Version : Mutual position of the QRadioButton Indicator and text



lotek
15th June 2011, 17:11
Hello,

Is it possible to style the QRadioButton (and maybe als the QCheckBox) so that the text can be on the left sight of the Indicator, or above it?

Thx for your help.

Santosh Reddy
16th June 2011, 05:53
Yes, it is possible. One way which I could suggest right way is use QStyleSheet with somthing like this


setStyleSheet(QString::fromUtf8("QCheckBox {\n"
" width: 10px;\n"
" spacing: -75px;\n"
"}\n"
"\n"
"QCheckBox::indicator {\n"
" subcontrol-origin: content;\n"
" subcontrol-position: right top;\n"
"}"));

" width: 10px;\n" - is required
" spacing: -75px;\n" - does the magic, and "-75" should be dynamically calculated based on your text rending length on screen, (may you build this into the custom QCheckBox class)

lotek
16th June 2011, 21:50
Thank you for the answer,

Unfortunately this does not work in my configuration (Qt 4.6 and SUSE 10.3).
The first issue - negative spacing shows the truncated text directly ON CheckBox (does no matter how many negative px is set), by the second issue the text disappears completely.
Maybe in the newer versions this will work correctly.

Added after 10 minutes:

p.s.
I hate these style sheets!
That's mixing of C++ with "something"!
Why there is no simply an according method for such operations?

wysota
17th June 2011, 01:00
Subclass QRadioButton, draw the indicator using QStyle, then draw the text where you need it using QPainter::drawText().

kochie
21st May 2015, 18:04
If you want the text on the left side and the icon on the right, you should be able to use:

radioButton->setLayoutDirection(Qt::RightToLeft);