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.platform as Platform
10
11/**
12 * A convenience wrapper combining QtQuick Controls ItemDelegate and IconTitleSubtitle
13 *
14 * This is an intentionally minimal wrapper that replaces the ItemDelegate's
15 * contentItem with an IconTitleSubtitle and adds a subtitle property.
16 *
17 * If you wish to customize the layout further, create your own `ItemDelegate`
18 * subclass with the `contentItem:` property set to the content of your choice.
19 * This can include `IconTitleSubtitle` inside a Layout, for example.
20 *
21 * \note If you don't need a subtitle, use `ItemDelegate` directly.
22 *
23 * \sa Kirigami::Delegates::TitleSubtitle
24 * \sa Kirigami::Delegates::IconTitleSubtitle
25 */
26QQC2.ItemDelegate {
27 id: delegate
28
29 // Developer note: This is intentional kept incredibly minimal as we want to
30 // reuse as much of upstream ItemDelegate as possible, the only extra thing
31 // being the subtitle property. Should that ever become an upstream feature,
32 // these controls will be removed in favour of using upstream's implementation
33 // directly.
35 /**
36 * The subtitle to display.
37 */
38 property string subtitle
39
40 QQC2.ToolTip.text: text + (subtitle.length > 0 ? "\n\n" + subtitle : "")
41 QQC2.ToolTip.visible: (Platform.Settings.tabletMode ? down : hovered) && (contentItem?.truncated ?? false)
42 QQC2.ToolTip.delay: Platform.Units.toolTipDelay
43
44 contentItem: IconTitleSubtitle {
45 icon: icon.fromControlsIcon(delegate.icon)
46 title: delegate.text
47 subtitle: delegate.subtitle
48 selected: delegate.highlighted || delegate.down
49 font: delegate.font
50 }
51}
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 Dec 13 2024 11:48:03 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.