Commit a85e24a0 authored by Jens Bache-Wiig's avatar Jens Bache-Wiig Committed by The Qt Project
Browse files

Improve GroupBox styling and content calculation


We need this to have expanding layouts.

Change-Id: I32ef9da90fa9210febaa23d3f579ec94f03c377d
Reviewed-by: default avatarJan Arve Sæther <jan-arve.saether@digia.com>
parent ee0303b0
No related merge requests found
Showing with 41 additions and 30 deletions
...@@ -130,18 +130,15 @@ Item { ...@@ -130,18 +130,15 @@ Item {
/*! /*!
This property holds the width of the content. This property holds the width of the content.
*/ */
readonly property real contentWidth: content.childrenRect.width + 2 * __margin property real contentWidth: content.childrenRect.width
/*! /*!
This property holds the height of the content. This property holds the height of the content.
*/ */
readonly property real contentHeight: content.childrenRect.height + 2 * __margin property real contentHeight: content.childrenRect.height
/*! \internal */ /*! \internal */
property int __margin: 8 property Component __style: Qt.createComponent(Settings.THEME_PATH + "/GroupBoxStyle.qml", groupbox)
/*! \internal */
property Component style: Qt.createComponent(Settings.THEME_PATH + "/GroupBoxStyle.qml", groupbox)
/*! \internal */ /*! \internal */
default property alias data: content.data default property alias data: content.data
...@@ -161,12 +158,16 @@ Item { ...@@ -161,12 +158,16 @@ Item {
id: loader id: loader
property alias control: groupbox property alias control: groupbox
anchors.fill: parent anchors.fill: parent
property int topMargin: (title.length > 0 || checkable ? 16 : 0) + __margin property int topMargin: (title.length > 0 || checkable ? 16 : 0) + content.margin
property int bottomMargin: 4 property int bottomMargin: 4
property int leftMargin: 4 property int leftMargin: 4
property int rightMargin: 4 property int rightMargin: 4
sourceComponent: style sourceComponent: styleLoader.item ? styleLoader.item.panel : null
onLoaded: item.z = -1 onLoaded: item.z = -1
Loader {
id: styleLoader
sourceComponent: __style
}
} }
CheckBox { CheckBox {
...@@ -185,10 +186,11 @@ Item { ...@@ -185,10 +186,11 @@ Item {
id:content id:content
z: 1 z: 1
focus: true focus: true
property int margin: styleLoader.item ? styleLoader.item.margin : 0
anchors.topMargin: loader.topMargin anchors.topMargin: loader.topMargin
anchors.leftMargin: __margin anchors.leftMargin: margin
anchors.rightMargin: __margin anchors.rightMargin: margin
anchors.bottomMargin: __margin anchors.bottomMargin: margin
anchors.fill: parent anchors.fill: parent
enabled: (!groupbox.checkable || groupbox.checked) enabled: (!groupbox.checkable || groupbox.checked)
} }
......
...@@ -40,15 +40,21 @@ ...@@ -40,15 +40,21 @@
import QtQuick 2.1 import QtQuick 2.1
import QtQuick.Controls 1.0 import QtQuick.Controls 1.0
import QtQuick.Controls.Private 1.0 import QtQuick.Controls.Private 1.0
import QtQuick.Controls.Styles 1.0
StyleItem {
id: styleitem Style {
elementType: "groupbox" property int margin: 8
text: control.title
on: control.checked property Component panel: StyleItem {
hasFocus: control.activeFocus id: styleitem
activeControl: checkable ? "checkbox" : "" elementType: "groupbox"
properties: { "checkable" : checkable , "sunken" : !flat} text: control.title
contentWidth: control.contentWidth on: control.checked
contentHeight: control.contentHeight hasFocus: control.activeFocus
activeControl: checkable ? "checkbox" : ""
properties: { "checkable" : checkable , "sunken" : !flat}
contentWidth: control.contentWidth + 2 * margin
contentHeight: control.contentHeight + 2 * margin
}
} }
...@@ -39,20 +39,23 @@ ...@@ -39,20 +39,23 @@
****************************************************************************/ ****************************************************************************/
import QtQuick 2.1 import QtQuick 2.1
import QtQuick.Controls 1.0 import QtQuick.Controls 1.0
import QtQuick.Controls.Styles 1.0
/*! /*!
\qmltype GroupBoxStyle \qmltype GroupBoxStyle
\internal \internal
\inqmlmodule QtQuick.Controls.Styles 1.0 \inqmlmodule QtQuick.Controls.Styles 1.0
*/ */
Item { Style {
implicitWidth: Math.max(200, contentWidth + 30) property int margin: 8
implicitHeight: contentHeight property Component panel: Item {
implicitWidth: Math.max(200, contentWidth + 30)
Text { implicitHeight: contentHeight
anchors.top: parent.top Text {
anchors.left: parent.left anchors.top: parent.top
anchors.margins: 4 anchors.left: parent.left
text: control.title anchors.margins: 4
text: control.title
}
} }
} }
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment