From 10458b3d4dc1ed9f06eece9d61d2e699e602117d Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Sat, 5 Dec 2015 12:35:08 +0100 Subject: GroupBox: add an example of a checkable groupbox Adjust the size calculation so that the example works smooth. Change-Id: Iaf25107b0cfaa3ceef0caeba120d1bd74c9bc854 Reviewed-by: Mitch Curtis --- src/imports/controls/GroupBox.qml | 6 ++- .../images/qtlabscontrols-groupbox-checkable.png | Bin 0 -> 8264 bytes .../snippets/qtlabscontrols-groupbox-checkable.qml | 48 +++++++++++++++++++++ src/imports/controls/material/GroupBox.qml | 6 ++- src/imports/controls/universal/GroupBox.qml | 6 ++- 5 files changed, 60 insertions(+), 6 deletions(-) create mode 100644 src/imports/controls/doc/images/qtlabscontrols-groupbox-checkable.png create mode 100644 src/imports/controls/doc/snippets/qtlabscontrols-groupbox-checkable.qml (limited to 'src/imports/controls') diff --git a/src/imports/controls/GroupBox.qml b/src/imports/controls/GroupBox.qml index 8504fae9..08866606 100644 --- a/src/imports/controls/GroupBox.qml +++ b/src/imports/controls/GroupBox.qml @@ -40,7 +40,9 @@ import Qt.labs.templates 1.0 as T T.GroupBox { id: control - implicitWidth: Math.max(background ? background.implicitWidth : 0, contentWidth + leftPadding + rightPadding) + implicitWidth: Math.max(background ? background.implicitWidth : 0, + label ? label.implicitWidth + leftPadding + rightPadding : 0, + contentWidth + leftPadding + rightPadding) implicitHeight: Math.max(background ? background.implicitHeight : 0, contentHeight + topPadding + bottomPadding) contentWidth: contentChildren.length === 1 ? contentChildren[0].implicitWidth : 0 @@ -48,7 +50,7 @@ T.GroupBox { spacing: 6 padding: 6 - topPadding: 6 + (label && title ? label.implicitHeight + spacing : 0) + topPadding: 6 + (label && label.implicitWidth > 0 ? label.implicitHeight + spacing : 0) //! [contentItem] contentItem: Item { } diff --git a/src/imports/controls/doc/images/qtlabscontrols-groupbox-checkable.png b/src/imports/controls/doc/images/qtlabscontrols-groupbox-checkable.png new file mode 100644 index 00000000..8b619b5b Binary files /dev/null and b/src/imports/controls/doc/images/qtlabscontrols-groupbox-checkable.png differ diff --git a/src/imports/controls/doc/snippets/qtlabscontrols-groupbox-checkable.qml b/src/imports/controls/doc/snippets/qtlabscontrols-groupbox-checkable.qml new file mode 100644 index 00000000..1c1232c7 --- /dev/null +++ b/src/imports/controls/doc/snippets/qtlabscontrols-groupbox-checkable.qml @@ -0,0 +1,48 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: http://www.gnu.org/copyleft/fdl.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtQuick.Layouts 1.0 +import Qt.labs.controls 1.0 + +//! [1] +GroupBox { + label: CheckBox { + id: checkBox + checked: true + text: qsTr("Synchronize") + } + + ColumnLayout { + anchors.fill: parent + enabled: checkBox.checked + CheckBox { text: qsTr("E-mail") } + CheckBox { text: qsTr("Calendar") } + CheckBox { text: qsTr("Contacts") } + } +} +//! [1] diff --git a/src/imports/controls/material/GroupBox.qml b/src/imports/controls/material/GroupBox.qml index de47ff14..cbdc585e 100644 --- a/src/imports/controls/material/GroupBox.qml +++ b/src/imports/controls/material/GroupBox.qml @@ -41,7 +41,9 @@ import Qt.labs.controls.material 1.0 T.GroupBox { id: control - implicitWidth: Math.max(background ? background.implicitWidth : 0, contentWidth + leftPadding + rightPadding) + implicitWidth: Math.max(background ? background.implicitWidth : 0, + label ? label.implicitWidth + leftPadding + rightPadding : 0, + contentWidth + leftPadding + rightPadding) implicitHeight: Math.max(background ? background.implicitHeight : 0, contentHeight + topPadding + bottomPadding) contentWidth: contentChildren.length === 1 ? contentChildren[0].implicitWidth : 0 @@ -49,7 +51,7 @@ T.GroupBox { spacing: 6 padding: 6 - topPadding: 6 + (label && title ? label.implicitHeight + spacing : 0) + topPadding: 6 + (label && label.implicitWidth > 0 ? label.implicitHeight + spacing : 0) //! [contentItem] contentItem: Item {} diff --git a/src/imports/controls/universal/GroupBox.qml b/src/imports/controls/universal/GroupBox.qml index cf7b7405..524203db 100644 --- a/src/imports/controls/universal/GroupBox.qml +++ b/src/imports/controls/universal/GroupBox.qml @@ -41,7 +41,9 @@ import Qt.labs.controls.universal 1.0 T.GroupBox { id: control - implicitWidth: Math.max(background ? background.implicitWidth : 0, contentWidth + leftPadding + rightPadding) + implicitWidth: Math.max(background ? background.implicitWidth : 0, + label ? label.implicitWidth + leftPadding + rightPadding : 0, + contentWidth + leftPadding + rightPadding) implicitHeight: Math.max(background ? background.implicitHeight : 0, contentHeight + topPadding + bottomPadding) contentWidth: contentChildren.length === 1 ? contentChildren[0].implicitWidth : 0 @@ -49,7 +51,7 @@ T.GroupBox { spacing: 12 padding: 12 - topPadding: 12 + (label && title ? label.implicitHeight + spacing : 0) + topPadding: 12 + (label && label.implicitWidth > 0 ? label.implicitHeight + spacing : 0) //! [contentItem] contentItem: Item { } -- cgit v1.2.3