开发者

Set QGroupBox title font size with style sheets

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.开发者_Python百科

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;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜