使用样式表设置 QGroupBox 标题字体大小
我希望能够使用样式表设置 QGroupBox 标题的字体大小。我似乎无法弄清楚。
根据我读过的内容
groupbox->setStyleSheet(style)
其中 style
是:
QGroupBox::title
{
subcontrol-origin: margin;
subcontrol-position: top left;
padding: 5 5px;
font-size: 18px;
font-weight: bold;
}
除了 font-size
和 font-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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
答案是“不”,
QGroupBox
的标题不支持QWidget::font
属性。我怀疑标题不是独立的QWidget
而是QGroupBox
小部件的一部分(因此由QGroupBox::paint()
绘制) 。但是,
GroupBox
小部件支持 font 属性,并且由于组框显示的唯一文本是其标题,因此您可以将字体样式应用到QGroupBox
小部件。The answer is "no", the title of a
QGroupBox
does not support theQWidget::font
property. I suspect that the title is not an independantQWidget
but a part of theQGroupBox
widget (thus drawn by theQGroupBox::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 theQGroupBox
widget.