Kirigami2

SwitchSubtitleDelegate.qml
1/*
2 * SPDX-FileCopyrightText: 2023 Arjen Hiemstra <ahiemstra@heimr.nl>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
7import QtQuick
8import QtQuick.Controls as QQC2
9import org.kde.kirigami as Kirigami
10import org.kde.kirigami.delegates as KD
11
12/**
13 * A convenience wrapper combining QtQuick Controls SwitchDelegate and IconTitleSubtitle
14 *
15 * This is an intentionally minimal wrapper that replaces the SwitchDelegate's
16 * contentItem with an IconTitleSubtitle and adds a subtitle property.
17 *
18 * If you wish to customize the layout further, create your own `SwitchDelegate`
19 * subclass with the `contentItem:` property set to the content of your choice.
20 * This can include `IconTitleSubtitle` inside a Layout, for example.
21 *
22 * \note If you don't need a subtitle, use `SwitchDelegate` directly.
23 *
24 * \sa Kirigami::Delegates::TitleSubtitle
25 * \sa Kirigami::Delegates::IconTitleSubtitle
26 */
27QQC2.SwitchDelegate {
28 id: delegate
29
30 // Please see the developer note in ItemDelegate
32 /**
33 * The subtitle to display.
34 */
35 property string subtitle
36
37 QQC2.ToolTip.text: text + (subtitle.length > 0 ? "\n\n" + subtitle : "")
38 QQC2.ToolTip.visible: (Kirigami.Settings.tabletMode ? down : hovered) && (contentItem?.truncated ?? false)
39 QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
40
41 contentItem: KD.IconTitleSubtitle {
42 icon: icon.fromControlsIcon(delegate.icon)
43 title: delegate.text
44 subtitle: delegate.subtitle
45 selected: delegate.highlighted || delegate.down
46 font: delegate.font
47 }
48}
A simple item containing an icon, title and subtitle.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 3 2024 11:49:34 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.