Center align text in radio button
-
Can we center align text in QRadioButton?
-
you could try it, using a style sheet:
@
QString szStyle = "QRadioButton {text-align: left;}";pRadio->setStyleSheet(szStyle);
@
-
Gerolf, but how do i center align the text.
-
Have you tried to replace left to center in Gerolf's sample?
-
How do define pRadio and in which file?
-
pRadio is your QRadioButton object.
-
Or set the stylesheet in Qt Designer or the designer view of Qt Creator.
-
QRadioButton {text-align: center;} didn't work for me. I am not sure if QT picks text-align for QRadioButton.
I was able to get the indicator center align, however then the text is left align to the indicator, so it is on the center but not properly align.
All I want is to center align the text as it gets for indicator.
-
I don't think you can do that. Perhaps you could work around it by using a QRadioButton without a label, a QLabel that is centered and and put them in a horizontal layout together?
-
not sure if text-align will be recognized.
Other approaches I'd try:-
You can create your own complex control as stated above
-
You can play with this: "http://developer.qt.nokia.com/faq/answer/how_can_i_draw_custom_subcontrols_for_a_complex_control":http://developer.qt.nokia.com/faq/answer/how_can_i_draw_custom_subcontrols_for_a_complex_control
-
can play with values below and get close to what you want ...
@
QRadioButton {
spacing: 5px;
}
QRadioButton::indicator {
width: 50px;
height: 13px;
}
@ -
You can try to edit/extend gui module to support this ...
see qcommonstyle.cpp and qstylesheetstyle.cpp, SE_RadioButtonIndicator and SE_RadioButtonLableSpacing are of interest to you
-
-
Is there a way I can find the size/width of the QRadiobutton text and adjust the spacing accordingly?
-
[quote author="NDev" date="1297325032"]Is there a way I can find the size/width of the QRadiobutton text and adjust the spacing accordingly? [/quote]
yes: text() is available. Also since a QRadioButton extends a QWidget: font(), fontinfo(), fontmetrics() are all available ..
-
Thanks. So how do I calculate the exact width my QRadioButton text is going to take?
-
the documentation should help.. just read through the docs for these QFont, QFontInfo and QFontMetrics .. you will get an idea