Kirigami2

ListSectionHeader.qml
1 /*
2  * SPDX-FileCopyrightText: 2019 Bj√∂rn Feber <[email protected]>
3  *
4  * SPDX-License-Identifier: LGPL-2.0-or-later
5  */
6 
7 import QtQuick 2.5
8 import QtQuick.Controls 2.15
9 import QtQuick.Layouts 1.2
10 import org.kde.kirigami 2.10 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  */
40 Kirigami.AbstractListItem {
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  separatorVisible: false
52  sectionDelegate: true
53  hoverEnabled: false
54 
55  activeFocusOnTab: false
56 
57  // we do not need a background
58  background: Item {}
59 
60  topPadding: Kirigami.Units.largeSpacing + Kirigami.Units.smallSpacing
61 
62  contentItem: RowLayout {
63  id: rowLayout
64  spacing: Kirigami.Units.largeSpacing
65 
66  Kirigami.Heading {
67  Layout.fillWidth: rowLayout.children.length === 1
68  Layout.alignment: Qt.AlignVCenter
69 
70  opacity: 0.7
71  level: 5
72  type: Kirigami.Heading.Primary
73  text: listSection.text
74  elide: Text.ElideRight
75 
76  // we override the Primary type's font weight (DemiBold) for Bold for contrast with small text
77  font.weight: Font.Bold
78  }
79 
80  Kirigami.Separator {
81  Layout.fillWidth: true
82  Layout.alignment: Qt.AlignVCenter
83  }
84  }
85 }
QChar * data()
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Feb 7 2023 04:14:23 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.