I would like to be able to set the font size of the title of a QGroupBox using style sheets. I can't seem to figure it out.
Based on what I've read here, I've come up with the following code. Unfortunately, it doesn't quite work.
groupbox->setStyleSheet(style)
Where style
is:
QGroupBox::title
{
subcontrol-origin: margin;
subcontrol-position: top left;
padding: 5 5px;
font-size: 18px;
font-weight: bold;
}
All of those style elements seem to be honored except font-size
and font-weight
. According to the Qt Style Sheets Reference, the font "property is supported by all widgets that respect the QWidget::font." Is this not the case for a QGroupBox's title?
The answer is "no", the title of a QGroupBox
does not support the QWidget::font
property. I suspect that the title is not an independant QWidget
but a part of the QGroupBox
widget (thus drawn by the QGroupBox::paint()
).
However, the GroupBox
widget supports the font property and since the only text displayed by a group box is its title, you can apply your font style to the QGroupBox
widget.
QGroupBox
{
font-size: 18px;
font-weight: bold;
}