diff options
author | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2022-08-24 11:28:00 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-08-31 22:48:31 +0000 |
commit | d26d6baeccc608aecf27115cd7c3ec8fe761653f (patch) | |
tree | 010286aeaaa2b57a74ed94a44b8674f3cad0ccdb /src | |
parent | 0faa066bb1609c8135c8e5c800bcae25aaff437d (diff) |
Fusion: add TreeViewDelegate
Add a version of TreeViewDelegate.qml to the Fusion
style, that looks more at home for that style (rather
than using the one in the Basic style).
This version is using the arrow-indicator from the
Fusion style as expand/collapse indicator, and
makes the height of each row match the height of a
normal Fusion button.
Change-Id: I153bb5776e23476cf8c383fb6f76e63981e28639
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 13a8df4a878a4f62e626b577cb92a2e0d0ba54c9)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/quickcontrols2/fusion/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/quickcontrols2/fusion/TreeViewDelegate.qml | 62 |
2 files changed, 63 insertions, 0 deletions
diff --git a/src/quickcontrols2/fusion/CMakeLists.txt b/src/quickcontrols2/fusion/CMakeLists.txt index 86a389822c..49bd660a65 100644 --- a/src/quickcontrols2/fusion/CMakeLists.txt +++ b/src/quickcontrols2/fusion/CMakeLists.txt @@ -51,6 +51,7 @@ set(qml_files "ToolButton.qml" "ToolSeparator.qml" "ToolTip.qml" + "TreeViewDelegate.qml" "Tumbler.qml" "VerticalHeaderView.qml" ) diff --git a/src/quickcontrols2/fusion/TreeViewDelegate.qml b/src/quickcontrols2/fusion/TreeViewDelegate.qml new file mode 100644 index 0000000000..5223361872 --- /dev/null +++ b/src/quickcontrols2/fusion/TreeViewDelegate.qml @@ -0,0 +1,62 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +import QtQuick +import QtQuick.Templates as T +import QtQuick.Controls.impl +import QtQuick.Controls.Fusion + +T.TreeViewDelegate { + id: control + + implicitWidth: leftMargin + __contentIndent + implicitContentWidth + rightPadding + rightMargin + implicitHeight: Math.max(implicitBackgroundHeight, implicitContentHeight, implicitIndicatorHeight) + + indentation: indicator ? indicator.width : 12 + leftMargin: 5 + rightMargin: 5 + spacing: 5 + + topPadding: contentItem ? (height - contentItem.implicitHeight) / 2 : 0 + leftPadding: !mirrored ? leftMargin + __contentIndent : width - leftMargin - __contentIndent - implicitContentWidth + + highlighted: control.selected || control.current + || ((control.treeView.selectionBehavior === TableView.SelectRows + || control.treeView.selectionBehavior === TableView.SelectionDisabled) + && control.row === control.treeView.currentRow) + + required property int row + required property var model + readonly property real __contentIndent: !isTreeNode ? 0 : (depth * indentation) + (indicator ? indicator.width + spacing : 0) + + indicator: Item { + readonly property real __indicatorIndent: control.leftMargin + (control.depth * control.indentation) + x: !control.mirrored ? __indicatorIndent : control.width - __indicatorIndent - width + y: (control.height - height) / 2 + implicitWidth: Math.max(arrow.implicitWidth, 20) + implicitHeight: 24 // same as Button.qml + + property ColorImage arrow : ColorImage { + parent: control.indicator + x: (parent.width - width) / 2 + y: (parent.height - height) / 2 + rotation: control.expanded ? 0 : (control.mirrored ? 90 : -90) + source: "qrc:/qt-project.org/imports/QtQuick/Controls/Fusion/images/arrow.png" + color: control.palette.windowText + defaultColor: "#353637" + } + } + + background: Rectangle { + implicitHeight: 24 // same as Button.qml + color: control.highlighted + ? control.palette.highlight + : (control.treeView.alternatingRows && control.row % 2 !== 0 + ? control.palette.alternateBase : control.palette.base) + } + + contentItem: Label { + text: control.model.display + elide: Text.ElideRight + } +} |