From 6cdd4b53031de17b36b30b00de0a6945470a35ad Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Wed, 19 Feb 2020 15:56:38 +0100 Subject: HeaderView: set implicitSize on the style items By setting an implicit size, the user don't need to set a width or height on a HeaderView himself, but it will get the default size recommended by the style. By doing it the way it's done in the patch we achieve the following: 1. A HeaderView will by default be resized to be the same size as the delegate. 2. If the application sets a size on HeaderView it that is larger than the implicit size of the delegate, the delegate will be resized to have the same size (effectively filling out the free space in the header). 3. If the size of HeaderView is smaller than the implicit size of the delegate, the delegate will simply be clipped. (effectivly saying that the implicitSize of the delegate is also it's minimum size). If this is not acceptable for the application, it will need to use a custom delegate. Since a HeaderView delegate is a component and not an item, it should not be a part of the sanity checks we do to avoid using internal IDs. Hence we blacklist until we have a better way of handling such cases. Task-number: QTPM-1300 Change-Id: I30ca3e13ce5e1371b60f5c4ecf742a7d7e794a36 Reviewed-by: Mitch Curtis --- src/imports/controls/HorizontalHeaderView.qml | 11 +++++++++-- src/imports/controls/VerticalHeaderView.qml | 11 +++++++++-- .../snippets/qtquickcontrols2-headerview-simple.qml | 4 ---- src/imports/controls/fusion/HorizontalHeaderView.qml | 11 +++++++++-- src/imports/controls/fusion/VerticalHeaderView.qml | 11 +++++++++-- .../controls/imagine/HorizontalHeaderView.qml | 11 +++++++++-- src/imports/controls/imagine/VerticalHeaderView.qml | 11 +++++++++-- .../controls/material/HorizontalHeaderView.qml | 11 +++++++++-- src/imports/controls/material/VerticalHeaderView.qml | 11 +++++++++-- .../controls/universal/HorizontalHeaderView.qml | 11 +++++++++-- .../controls/universal/VerticalHeaderView.qml | 11 +++++++++-- tests/auto/sanity/BLACKLIST | 20 ++++++++++++++++++++ tests/manual/headerview/main.qml | 4 ---- 13 files changed, 110 insertions(+), 28 deletions(-) diff --git a/src/imports/controls/HorizontalHeaderView.qml b/src/imports/controls/HorizontalHeaderView.qml index 946d3a75..7f0454da 100644 --- a/src/imports/controls/HorizontalHeaderView.qml +++ b/src/imports/controls/HorizontalHeaderView.qml @@ -41,13 +41,20 @@ import QtQuick.Templates 2.15 as T T.HorizontalHeaderView { id: control + implicitWidth: syncView ? syncView.width : 0 + implicitHeight: contentHeight + delegate: Rectangle { - implicitWidth: 50 - implicitHeight: 25 + // Qt6: add cellPadding (and font etc) as public API in headerview + readonly property real cellPadding: 8 + + implicitWidth: text.implicitWidth + (cellPadding * 2) + implicitHeight: Math.max(control.height, text.implicitHeight + (cellPadding * 2)) color: "#f6f6f6" border.color: "#e4e4e4" Text { + id: text text: model[control.textRole] width: parent.width height: parent.height diff --git a/src/imports/controls/VerticalHeaderView.qml b/src/imports/controls/VerticalHeaderView.qml index 67d4c1ce..5fbfaedf 100644 --- a/src/imports/controls/VerticalHeaderView.qml +++ b/src/imports/controls/VerticalHeaderView.qml @@ -41,13 +41,20 @@ import QtQuick.Templates 2.15 as T T.VerticalHeaderView { id: control + implicitWidth: contentWidth + implicitHeight: syncView ? syncView.height : 0 + delegate: Rectangle { - implicitWidth: 50 - implicitHeight: 25 + // Qt6: add cellPadding (and font etc) as public API in headerview + readonly property real cellPadding: 8 + + implicitWidth: Math.max(control.width, text.implicitWidth + (cellPadding * 2)) + implicitHeight: text.implicitHeight + (cellPadding * 2) color: "#f6f6f6" border.color: "#e4e4e4" Text { + id: text text: model[control.textRole] width: parent.width height: parent.height diff --git a/src/imports/controls/doc/snippets/qtquickcontrols2-headerview-simple.qml b/src/imports/controls/doc/snippets/qtquickcontrols2-headerview-simple.qml index bea46bf3..07ec84d8 100644 --- a/src/imports/controls/doc/snippets/qtquickcontrols2-headerview-simple.qml +++ b/src/imports/controls/doc/snippets/qtquickcontrols2-headerview-simple.qml @@ -63,8 +63,6 @@ ApplicationWindow { id: horizontalHeader syncView: tableView anchors.left: tableView.left - width: parent.width - height: contentHeight } //! [horizontal] @@ -73,8 +71,6 @@ ApplicationWindow { id: verticalHeader syncView: tableView anchors.top: tableView.top - width: contentWidth - height: parent.height } //! [vertical] diff --git a/src/imports/controls/fusion/HorizontalHeaderView.qml b/src/imports/controls/fusion/HorizontalHeaderView.qml index 0be27642..3d0f247b 100644 --- a/src/imports/controls/fusion/HorizontalHeaderView.qml +++ b/src/imports/controls/fusion/HorizontalHeaderView.qml @@ -41,9 +41,15 @@ import QtQuick.Templates 2.15 as T T.HorizontalHeaderView { id: control + implicitWidth: syncView ? syncView.width : 0 + implicitHeight: contentHeight + delegate: Rectangle { - implicitWidth: 50 - implicitHeight: 25 + // Qt6: add cellPadding (and font etc) as public API in headerview + readonly property real cellPadding: 8 + + implicitWidth: text.implicitWidth + (cellPadding * 2) + implicitHeight: Math.max(control.height, text.implicitHeight + (cellPadding * 2)) border.color: "#cacaca" gradient: Gradient { @@ -58,6 +64,7 @@ T.HorizontalHeaderView { } Text { + id: text text: model[control.textRole] width: parent.width height: parent.height diff --git a/src/imports/controls/fusion/VerticalHeaderView.qml b/src/imports/controls/fusion/VerticalHeaderView.qml index a9eadc23..5ad0db8f 100644 --- a/src/imports/controls/fusion/VerticalHeaderView.qml +++ b/src/imports/controls/fusion/VerticalHeaderView.qml @@ -41,9 +41,15 @@ import QtQuick.Templates 2.15 as T T.VerticalHeaderView { id: control + implicitWidth: contentWidth + implicitHeight: syncView ? syncView.height : 0 + delegate: Rectangle { - implicitWidth: 50 - implicitHeight: 25 + // Qt6: add cellPadding (and font etc) as public API in headerview + readonly property real cellPadding: 8 + + implicitWidth: Math.max(control.width, text.implicitWidth + (cellPadding * 2)) + implicitHeight: text.implicitHeight + (cellPadding * 2) border.color: "#cacaca" gradient: Gradient { @@ -58,6 +64,7 @@ T.VerticalHeaderView { } Text { + id: text text: model[control.textRole] width: parent.width height: parent.height diff --git a/src/imports/controls/imagine/HorizontalHeaderView.qml b/src/imports/controls/imagine/HorizontalHeaderView.qml index 946d3a75..7f0454da 100644 --- a/src/imports/controls/imagine/HorizontalHeaderView.qml +++ b/src/imports/controls/imagine/HorizontalHeaderView.qml @@ -41,13 +41,20 @@ import QtQuick.Templates 2.15 as T T.HorizontalHeaderView { id: control + implicitWidth: syncView ? syncView.width : 0 + implicitHeight: contentHeight + delegate: Rectangle { - implicitWidth: 50 - implicitHeight: 25 + // Qt6: add cellPadding (and font etc) as public API in headerview + readonly property real cellPadding: 8 + + implicitWidth: text.implicitWidth + (cellPadding * 2) + implicitHeight: Math.max(control.height, text.implicitHeight + (cellPadding * 2)) color: "#f6f6f6" border.color: "#e4e4e4" Text { + id: text text: model[control.textRole] width: parent.width height: parent.height diff --git a/src/imports/controls/imagine/VerticalHeaderView.qml b/src/imports/controls/imagine/VerticalHeaderView.qml index 67d4c1ce..5fbfaedf 100644 --- a/src/imports/controls/imagine/VerticalHeaderView.qml +++ b/src/imports/controls/imagine/VerticalHeaderView.qml @@ -41,13 +41,20 @@ import QtQuick.Templates 2.15 as T T.VerticalHeaderView { id: control + implicitWidth: contentWidth + implicitHeight: syncView ? syncView.height : 0 + delegate: Rectangle { - implicitWidth: 50 - implicitHeight: 25 + // Qt6: add cellPadding (and font etc) as public API in headerview + readonly property real cellPadding: 8 + + implicitWidth: Math.max(control.width, text.implicitWidth + (cellPadding * 2)) + implicitHeight: text.implicitHeight + (cellPadding * 2) color: "#f6f6f6" border.color: "#e4e4e4" Text { + id: text text: model[control.textRole] width: parent.width height: parent.height diff --git a/src/imports/controls/material/HorizontalHeaderView.qml b/src/imports/controls/material/HorizontalHeaderView.qml index a1228cdc..504579cc 100644 --- a/src/imports/controls/material/HorizontalHeaderView.qml +++ b/src/imports/controls/material/HorizontalHeaderView.qml @@ -43,12 +43,19 @@ import QtQuick.Controls.Material.impl 2.15 T.HorizontalHeaderView { id: control + implicitWidth: syncView ? syncView.width : 0 + implicitHeight: contentHeight + delegate: Rectangle { - implicitWidth: 50 - implicitHeight: 25 + // Qt6: add cellPadding (and font etc) as public API in headerview + readonly property real cellPadding: 8 + + implicitWidth: text.implicitWidth + (cellPadding * 2) + implicitHeight: Math.max(control.height, text.implicitHeight + (cellPadding * 2)) color: control.Material.backgroundColor Text { + id: text text: model[control.textRole] width: parent.width height: parent.height diff --git a/src/imports/controls/material/VerticalHeaderView.qml b/src/imports/controls/material/VerticalHeaderView.qml index 8acda3d7..7f8ecc92 100644 --- a/src/imports/controls/material/VerticalHeaderView.qml +++ b/src/imports/controls/material/VerticalHeaderView.qml @@ -43,12 +43,19 @@ import QtQuick.Controls.Material.impl 2.15 T.VerticalHeaderView { id: control + implicitWidth: contentWidth + implicitHeight: syncView ? syncView.height : 0 + delegate: Rectangle { - implicitWidth: 50 - implicitHeight: 25 + // Qt6: add cellPadding (and font etc) as public API in headerview + readonly property real cellPadding: 8 + + implicitWidth: Math.max(control.width, text.implicitWidth + (cellPadding * 2)) + implicitHeight: text.implicitHeight + (cellPadding * 2) color: control.Material.backgroundColor Text { + id: text text: model[control.textRole] width: parent.width height: parent.height diff --git a/src/imports/controls/universal/HorizontalHeaderView.qml b/src/imports/controls/universal/HorizontalHeaderView.qml index 6f48560e..8cdfda35 100644 --- a/src/imports/controls/universal/HorizontalHeaderView.qml +++ b/src/imports/controls/universal/HorizontalHeaderView.qml @@ -44,12 +44,19 @@ import QtQuick.Controls.Universal.impl 2.15 T.HorizontalHeaderView { id: control + implicitWidth: syncView ? syncView.width : 0 + implicitHeight: contentHeight + delegate: Rectangle { - implicitWidth: 50 - implicitHeight: 25 + // Qt6: add cellPadding (and font etc) as public API in headerview + readonly property real cellPadding: 8 + + implicitWidth: text.implicitWidth + (cellPadding * 2) + implicitHeight: Math.max(control.height, text.implicitHeight + (cellPadding * 2)) color: control.Universal.background Text { + id: text text: model[control.textRole] width: parent.width height: parent.height diff --git a/src/imports/controls/universal/VerticalHeaderView.qml b/src/imports/controls/universal/VerticalHeaderView.qml index 80133dbd..7c7544af 100644 --- a/src/imports/controls/universal/VerticalHeaderView.qml +++ b/src/imports/controls/universal/VerticalHeaderView.qml @@ -44,12 +44,19 @@ import QtQuick.Controls.Universal.impl 2.15 T.VerticalHeaderView { id: control + implicitWidth: contentWidth + implicitHeight: syncView ? syncView.height : 0 + delegate: Rectangle { - implicitWidth: 50 - implicitHeight: 25 + // Qt6: add cellPadding (and font etc) as public API in headerview + readonly property real cellPadding: 8 + + implicitWidth: Math.max(control.width, text.implicitWidth + (cellPadding * 2)) + implicitHeight: text.implicitHeight + (cellPadding * 2) color: control.Universal.background Text { + id: text text: model[control.textRole] width: parent.width height: parent.height diff --git a/tests/auto/sanity/BLACKLIST b/tests/auto/sanity/BLACKLIST index 42ad3448..2a157b87 100644 --- a/tests/auto/sanity/BLACKLIST +++ b/tests/auto/sanity/BLACKLIST @@ -2,3 +2,23 @@ * [attachedObjects:material/SwitchDelegate.qml] * +[ids:controls/HorizontalHeaderView.qml] +* +[ids:controls/VerticalHeaderView.qml] +* +[ids:fusion/HorizontalHeaderView.qml] +* +[ids:fusion/VerticalHeaderView.qml] +* +[ids:imagine/HorizontalHeaderView.qml] +* +[ids:imagine/VerticalHeaderView.qml] +* +[ids:material/HorizontalHeaderView.qml] +* +[ids:material/VerticalHeaderView.qml] +* +[ids:universal/HorizontalHeaderView.qml] +* +[ids:universal/VerticalHeaderView.qml] +* diff --git a/tests/manual/headerview/main.qml b/tests/manual/headerview/main.qml index 2919f1b2..ab9c3dc5 100644 --- a/tests/manual/headerview/main.qml +++ b/tests/manual/headerview/main.qml @@ -101,8 +101,6 @@ Window { HorizontalHeaderView { id: horizontalHeader objectName: "horizontalHeader" - height: contentHeight - width: syncView.width anchors.top: parent.top anchors.left: tableView.left syncView: tableView @@ -112,8 +110,6 @@ Window { VerticalHeaderView { id: verticalHeader objectName: "verticalHeader" - width: contentWidth - height: syncView.height anchors.top: tableView.top syncView: tableView clip: true -- cgit v1.2.3