Kirigami2

SubtitleDelegate.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 ItemDelegate and IconTitleSubtitle
14 *
15 * This is an intentionally minimal wrapper that replaces the ItemDelegate's
16 * contentItem with an IconTitleSubtitle and adds a subtitle property.
17 *
18 * If you wish to customize the layout further, create your own `ItemDelegate`
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 `ItemDelegate` directly.
23 *
24 * \sa Kirigami::Delegates::TitleSubtitle
25 * \sa Kirigami::Delegates::IconTitleSubtitle
26 */
27QQC2.ItemDelegate {
28 id: delegate
29
30 // Developer note: This is intentional kept incredibly minimal as we want to
31 // reuse as much of upstream ItemDelegate as possible, the only extra thing
32 // being the subtitle property. Should that ever become an upstream feature,
33 // these controls will be removed in favour of using upstream's implementation
34 // directly.
36 /**
37 * The subtitle to display.
38 */
39 property string subtitle
40
41 QQC2.ToolTip.text: text + (subtitle.length > 0 ? "\n\n" + subtitle : "")
42 QQC2.ToolTip.visible: (Kirigami.Settings.tabletMode ? down : hovered) && (contentItem?.truncated ?? false)
43 QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
44
45 contentItem: KD.IconTitleSubtitle {
46 icon: icon.fromControlsIcon(delegate.icon)
47 title: delegate.text
48 subtitle: delegate.subtitle
49 selected: delegate.highlighted || delegate.down
50 font: delegate.font
51 }
52}
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.