Kirigami2

CheckableListItem.qml
1 /*
2  * SPDX-FileCopyrightText: 2020 Nate Graham <[email protected]>
3  *
4  * SPDX-License-Identifier: LGPL-2.0-or-later
5  */
6 
7 import QtQuick 2.1
8 import QtQuick.Layouts 1.2
9 import QtQuick.Controls 2.0 as QQC2
10 import org.kde.kirigami 2.14 as Kirigami
11 
12 /**
13  * A simple subclass of BasicListItem that adds a checkbox on the left side of
14  * the layout. The list item's own checked: property controls the check state
15  * of the checkbox.
16  *
17  * When the list item or its checkbox is clicked, the QQC2 action specified in
18  * the' list item's actions: property will be triggered.
19  *
20  * @note Due to the way BasicListItem works, the QQC2 action MUST contain the
21  * line "checked = !checked" as the first line within its "onTriggered:" handler.
22  *
23  * Example usage:
24  *
25  * @code{.qml}
26  * import org.kde.kirigami 2.14 as Kirigami
27  *
28  * ListView {
29  * id: listView
30  * model: [...]
31  * delegate: Kirigami.CheckableListItem {
32  * label: model.display
33  *
34  * checked: model.checked
35  *
36  * action: Action {
37  * onTriggered: {
38  * checked = !checked
39  * [ do something amazing ]
40  * }
41  * }
42  * }
43  * }
44  * @endcode
45  * @since 2.14
46  * @inherit org::kde::kirigami::BasicListItem
47  */
48 Kirigami.BasicListItem {
49  id: checkableListItem
50 
51  checkable: true
52  activeBackgroundColor: "transparent"
53  activeTextColor: Kirigami.Theme.textColor
54 
55  leading: QQC2.CheckBox {
56  checked: checkableListItem.checked
57  onToggled: {
58  checkableListItem.action.trigger();
59  }
60  }
61 }
Definition: icon.h:18
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Thu Dec 2 2021 22:35:32 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.