diff options
author | Jan Arve Sæther <jan-arve.saether@qt.io> | 2020-06-09 14:17:29 +0200 |
---|---|---|
committer | Jan Arve Sæther <jan-arve.saether@qt.io> | 2020-06-10 12:32:58 +0000 |
commit | 729d147a57cc47864f833273fde18f0335fb9655 (patch) | |
tree | 556d82d9412a8d15f68613b8cad5fabdc75446d6 | |
parent | 94268de55368b9f433d78effad132d1370054286 (diff) |
Fix issues with the label in GroupBox
1. Make it have the correct position, given by the labelPos
property.
2. Put a Rectangle with the background color below the label to wipe
away the frame strikethrough.
Change-Id: I68b6f1b5fda7854f7032dd9716613d025d2eb6ed
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
3 files changed, 33 insertions, 10 deletions
diff --git a/src/imports/nativestyle/controls/DefaultGroupBox.qml b/src/imports/nativestyle/controls/DefaultGroupBox.qml index a8c39c7a..0d29fd7d 100644 --- a/src/imports/nativestyle/controls/DefaultGroupBox.qml +++ b/src/imports/nativestyle/controls/DefaultGroupBox.qml @@ -53,15 +53,25 @@ T.GroupBox { font.pixelSize: nativeBackground ? background.styleFont(control).pixelSize : undefined - label: Text { - x: control.leftPadding - width: control.availableWidth - - text: control.title - font: control.font - color: control.palette.windowText - elide: Text.ElideRight - verticalAlignment: Text.AlignVCenter + label: Rectangle { + color: control.palette.window + property point labelPos : control.nativeBackground + ? background.labelPos + : Qt.point(0,0) + x: labelPos.x + background.x + y: labelPos.y + background.y - groupBoxPadding.top + width: txt.implicitWidth + height: txt.implicitHeight + Text { + id: txt + width: parent.width + height: parent.height + text: control.title + font: control.font + color: control.palette.windowText + elide: Text.ElideRight + verticalAlignment: Text.AlignVCenter + } } leftPadding: nativeBackground ? background.contentPadding.left : 0 diff --git a/src/imports/nativestyle/items/qquickstyleitemgroupbox.cpp b/src/imports/nativestyle/items/qquickstyleitemgroupbox.cpp index 2b4154d2..d62b6f23 100644 --- a/src/imports/nativestyle/items/qquickstyleitemgroupbox.cpp +++ b/src/imports/nativestyle/items/qquickstyleitemgroupbox.cpp @@ -68,6 +68,10 @@ StyleItemGeometry QQuickStyleItemGroupBox::calculateGeometry() if (m_groupBoxPadding != oldGroupBoxPadding) emit groupBoxPaddingChanged(); + const QPointF oldLabelPos = m_labelPos; + m_labelPos = style()->subControlRect(QStyle::CC_GroupBox, &styleOption, QStyle::SC_GroupBoxLabel).topLeft(); + if (m_labelPos != oldLabelPos) + emit labelPosChanged(); return geometry; } @@ -89,3 +93,8 @@ QQuickStyleMargins QQuickStyleItemGroupBox::groupBoxPadding() const { return m_groupBoxPadding; } + +QPointF QQuickStyleItemGroupBox::labelPos() const +{ + return m_labelPos; +} diff --git a/src/imports/nativestyle/items/qquickstyleitemgroupbox.h b/src/imports/nativestyle/items/qquickstyleitemgroupbox.h index 8e65855c..efb6d4f6 100644 --- a/src/imports/nativestyle/items/qquickstyleitemgroupbox.h +++ b/src/imports/nativestyle/items/qquickstyleitemgroupbox.h @@ -43,15 +43,18 @@ class QQuickStyleItemGroupBox : public QQuickStyleItem { Q_OBJECT - Q_PROPERTY(QQuickStyleMargins groupBoxPadding READ groupBoxPadding() NOTIFY groupBoxPaddingChanged) + Q_PROPERTY(QQuickStyleMargins groupBoxPadding READ groupBoxPadding NOTIFY groupBoxPaddingChanged) + Q_PROPERTY(QPointF labelPos READ labelPos NOTIFY labelPosChanged) QML_NAMED_ELEMENT(GroupBox) public: QQuickStyleMargins groupBoxPadding() const; + QPointF labelPos() const; QFont styleFont(QQuickItem *control) override; signals: void groupBoxPaddingChanged(); + void labelPosChanged(); protected: void paintEvent(QPainter *painter) override; @@ -59,6 +62,7 @@ protected: private: QQuickStyleMargins m_groupBoxPadding; + QPointF m_labelPos; void initStyleOption(QStyleOptionGroupBox &styleOption); }; |