使用样式表设置 QGroupBox 标题字体大小 [英] Set QGroupBox title font size with style sheets

查看:269
本文介绍了使用样式表设置 QGroupBox 标题字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够使用样式表设置 QGroupBox 标题的字体大小.我似乎无法弄清楚.

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)

style 在哪里:

QGroupBox::title
{
    subcontrol-origin: margin;
    subcontrol-position: top left;
    padding: 5 5px;
    font-size: 18px;
    font-weight: bold;
}

除了 font-sizefont-weight 之外,所有这些样式元素似乎都受到尊重.根据 Qt 样式表参考,字体所有尊重 QWidget::font 的小部件都支持属性."QGroupBox的标题不是这样吗?

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?

推荐答案

答案是否定的,QGroupBox的标题不支持QWidget::font 财产.我怀疑标题不是独立的 QWidget 而是 QGroupBox 小部件的一部分(因此由 QGroupBox::paint() 绘制).

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()).

但是,GroupBox 小部件支持字体属性,并且由于组框显示的唯一文本是其标题,您可以将字体样式应用于 QGroupBox 小部件.

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

这篇关于使用样式表设置 QGroupBox 标题字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆