diff options
author | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2020-02-19 15:56:38 +0100 |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2020-03-10 08:51:31 +0100 |
commit | 6cdd4b53031de17b36b30b00de0a6945470a35ad (patch) | |
tree | ca5546c6c8e3a97ed657a0122e52dc7b55fb9f18 /src/imports/controls/HorizontalHeaderView.qml | |
parent | 9f093c8e491b647928d01580761238e931d3ea13 (diff) |
HeaderView: set implicitSize on the style itemsv5.15.0-beta2
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 <mitch.curtis@qt.io>
Diffstat (limited to 'src/imports/controls/HorizontalHeaderView.qml')
-rw-r--r-- | src/imports/controls/HorizontalHeaderView.qml | 11 |
1 files changed, 9 insertions, 2 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 |