Ivan Kush
Ivan Kush

Reputation: 3157

GroupBox internal margins

I set margins of label and label2 to zero relatively to internal groupBox2. As can be seen from the picture, label is along the border of groupBox2 while label2 has the additional margin.

What is the internal margin of GroupBox?

enter image description here

GroupBox {
    id: groupBox1
    x: 5
    y: 302
    width: 142
    height: 90
    checked: false
    flat: false
    title: qsTr("Group Box")

    Label {
        id: label
        text: qsTr("Label")
        anchors.top: parent.top
        anchors.topMargin: 0
        anchors.left: groupBox2.left
        anchors.leftMargin: 0
    }

    GroupBox {
        id: groupBox2
        y: 16
        height: 45
        anchors.bottom: parent.bottom
        anchors.bottomMargin: 0
        anchors.right: parent.right
        anchors.rightMargin: 0
        anchors.left: parent.left
        anchors.leftMargin: 0
        title: qsTr("Group Box2")

        Label {
            id: label2
            text: qsTr("Label2")
            anchors.left: parent.left
            anchors.leftMargin: 0
        }
    }
}

Upvotes: 1

Views: 3555

Answers (1)

Krzysztof Piekutowski
Krzysztof Piekutowski

Reputation: 674

GroupBox has style which defines internal margins and their size depends on the platform your program is running on.

Check out GroupBox style in your qt installation directory e.g. /path_to_installation/Qt5.5.0/5.5/Src/qtquickcontrols/src/controls/Styles/Base/GroupBoxStyle.qml, there are also custom styles in subdirectories for various platforms: Desktop/GroupBoxStyle.qml, WinRT/PC/GroupBoxStyle.qml, iOS/GroupBoxStyle.qml, etc.

Here's part from Base/GroupBoxStyle.qml:

/*! The margin from the content item to the groupbox. */
padding {
    top: (control.title.length > 0 || control.checkable ? TextSingleton.implicitHeight : 0) + 10
    left: 8
    right: 8
    bottom: 6
}

So left margin is probably set to 8 in your case.

GroupBox has undocumented property style which can be used to set custom style. GroupBox.style and GroupBoxStyle.qml are marked as internal so be careful when updating Qt, they can be changed in future Qt releases without warning and code using it could stop working.

So to set different margin size you could copy GroupBoxStyle.qml to your project and use it like this:

GroupBox {
    style: GroupBoxStyle {
        padding.left: 0 //your desired padding value
    }
}

Upvotes: 3

Related Questions