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/imagine/HorizontalHeaderView.qml | 11 +++++++++-- src/imports/controls/imagine/VerticalHeaderView.qml | 11 +++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) (limited to 'src/imports/controls/imagine') 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 -- cgit v1.2.3