qt - 调整 QGroupBox 中的标题位置(使用样式表)

标签 qt qtstylesheets qgroupbox

我正在尝试设置 QGroupBox 的样式来满足某些设计要求:

enter image description here

注意 - 顶部的组标题应位于左侧,但超过框曲率。

使用以下样式表,我得到下面的图像(如果删除“左”一词,则为第二张图像):

QGroupBox {
    font: bold; 
    border: 1px solid silver;
    border-radius: 6px;
    margin-top: 6px;
}
QGroupBox::title {
    subcontrol-origin:  margin;
    subcontrol-position: top left;    // for second image:  top; 
    padding: 0 2px 0 2px;
}

enter image description here enter image description here

所以,看来我想要的是 subcontrol-position: top left; 但有一个添加的偏移量。我在任何地方都找不到。

添加填充会删除该行,所以这不是我想要的。

我刚才发现了一个选项 - subcontrol-origin: 的另一个选项:

QGroupBox::title {
    subcontrol-origin:  padding;
    subcontrol-position: top left; 
    padding: -16 12px 0 12px;
}

看起来几乎正确 - 但边框现在穿过了标题。

enter image description here

如何移动组框的标题,使其仍然位于左侧但超过框曲率,并且曲率保持可见,例如在设计中?

最佳答案

应用以下样式:

QGroupBox {
    font: bold;
    border: 1px solid silver;
    border-radius: 6px;
    margin-top: 6px;
}

QGroupBox::title {
    subcontrol-origin: margin;
    left: 7px;
    padding: 0px 5px 0px 5px;
}

我得到这样的东西:

enter image description here

关于qt - 调整 QGroupBox 中的标题位置(使用样式表),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42655988/

相关文章:

python - 如何在 PySide2 中正确使用 CSS

c++ - 如何在 Qt 样式表中使用嵌入字体?

python - QGridlayout 和 QGroupbox 对齐

c++ - 从 "fusion"样式的 QTreeView 中删除蓝色选择

c++ - Qt:自动向QGroupbox添加滚动条

python - Pyqt:如何更改QGroupBox标题颜色?

c++ - 如何将嵌套模式与 QRegularExpression 匹配?

c++ - 未声明的标识符 'QVariant' 将旧版 Qt 4 转换为 5

qt - 在 ListView 之间传递焦点

c++ - 如何在 Qt/C++ 中存储加密设置?