使用样式表设置 QGroupBox 标题字体大小

发布于 2024-08-30 10:01:24 字数 584 浏览 2 评论 0原文

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

根据我读过的内容

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 的标题不就是这种情况吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

热鲨 2024-09-06 10:01:24

答案是“不”,QGroupBox 的标题不支持 QWidget::font 属性。我怀疑标题不是独立的 QWidget 而是 QGroupBox 小部件的一部分(因此由 QGroupBox::paint() 绘制) 。

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

QGroupBox
{
    font-size: 18px;
    font-weight: bold;
}

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文