Kirigami2

ListSectionHeader.qml
1/*
2 * SPDX-FileCopyrightText: 2019 Björn Feber <bfeber@protonmail.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
7import QtQuick
8import QtQuick.Controls
9import QtQuick.Layouts
10import org.kde.kirigami as Kirigami
11
12/**
13 * @brief A section delegate for the primitive ListView component.
14 *
15 * It's intended to make all listviews look coherent.
16 *
17 * Example usage:
18 * @code
19 * import QtQuick 2.5
20 * import QtQuick.Controls 2.5 as QQC2
21 *
22 * import org.kde.kirigami 2.10 as Kirigami
23 *
24 * ListView {
25 * [...]
26 * section.delegate: Kirigami.ListSectionHeader {
27 * label: section
28 *
29 * QQC2.Button {
30 * text: "Button 1"
31 * }
32 * QQC2.Button {
33 * text: "Button 2"
34 * }
35 * }
36 * [...]
37 * }
38 * @endcode
39 */
40ItemDelegate {
41 id: listSection
42
43 /**
44 * @brief This property sets the text of the ListView's section header.
45 * @property string label
46 */
47 property alias label: listSection.text
48
49 default property alias _contents: rowLayout.data
50
51 hoverEnabled: false
52
53 activeFocusOnTab: false
54
55 // we do not need a background
56 background: Item {}
57
58 topPadding: Kirigami.Units.largeSpacing + Kirigami.Units.smallSpacing
59
60 contentItem: RowLayout {
61 id: rowLayout
62 spacing: Kirigami.Units.largeSpacing
63
64 Kirigami.Heading {
65 Layout.maximumWidth: rowLayout.width
66 Layout.alignment: Qt.AlignVCenter
67
68 opacity: 0.7
69 level: 5
70 type: Kirigami.Heading.Primary
71 text: listSection.text
72 elide: Text.ElideRight
73
74 // we override the Primary type's font weight (DemiBold) for Bold for contrast with small text
75 font.weight: Font.Bold
76
77 Accessible.ignored: true
78 }
79
80 Kirigami.Separator {
81 Layout.fillWidth: true
82 Layout.alignment: Qt.AlignVCenter
83 Accessible.ignored: true
84 }
85 }
86}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:18:46 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.