Kirigami2

DialogHeaderTopContent.qml
1/*
2 SPDX-FileCopyrightText: 2021 Devin Lin <espidev@gmail.com>
3 SPDX-FileCopyrightText: 2021 Noah Davis <noahadvs@gmail.com>
4 SPDX-FileCopyrightText: 2022 ivan tkachenko <me@ratijas.tk>
5 SPDX-FileCopyrightText: 2025 Nate Graham <nate@kde.org>
6 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
7 */
8
9import QtQuick
10import QtQuick.Layouts
11import QtQuick.Templates as T
12import QtQuick.Controls as QQC2
13import org.kde.kirigami as Kirigami
14
15/**
16 * @brief Standard top content for a Dialog, including header text and an
17 * optional close button.
18 *
19 * Provides appropriate padding and a bottom separator when the dialog's content
20 * is scrollable.
21 *
22 * Chiefly useful as the first item in a `ColumnLayout` inside a custom header,
23 * for when you want a custom header that only consists of extra content, and
24 * does not need to override the standard content. Example usage for a this:
25 *
26 * @code{.qml}
27 * import QtQuick
28 * import QtQuick.Layouts
29 * import org.kde.kirigami as Kirigami
30 * import org.kde.kirigami.dialogs as KDialogs
31 *
32 * Kirigami.Dialog {
33 * id: myDialog
34 *
35 * title: i18n("My Dialog")
36 *
37 * standardButtons: Kirigami.Dialog.Ok | Kirigami.Dialog.Cancel
38 *
39 * header: KDialogs.DialogHeader {
40 * dialog: myDialog
41 *
42 * contentItem: ColumnLayout {
43 * Spacing: Kirigami.Units.smallSpacing
44 *
45 * KDialogs.DialogHeaderTopContent {
46 * dialog: myDialog
47 * }
48 *
49 * [...]
50 * }
51 * }
52 * [...]
53 * }
54 * @endcode
55 * @inherit T.Control
56 */
57RowLayout {
58 id: root
59
60 /**
61 * @brief This property points to the parent dialog, some of whose properties
62 * need to be available here.
63 * @property T.Dialog dialog
64 */
65 required property T.Dialog dialog
66
67 spacing: Kirigami.Units.smallSpacing
68
69 Kirigami.Heading {
70 Layout.fillWidth: true
71 Layout.alignment: Qt.AlignVCenter
72
73 text: root.dialog.title.length === 0 ? " " : root.dialog.title // always have text to ensure header height
74 elide: Text.ElideRight
75
76 // use tooltip for long text that is elided
77 QQC2.ToolTip.visible: truncated && titleHoverHandler.hovered
78 QQC2.ToolTip.text: root.dialog.title
79
80 HoverHandler {
81 id: titleHoverHandler
82 }
83 }
84
85 QQC2.ToolButton {
86 Layout.alignment: Qt.AlignRight | Qt.AlignTop
87
88 icon.name: hovered ? "window-close" : "window-close-symbolic"
89 text: qsTr("Close", "@action:button close dialog")
90 display: QQC2.AbstractButton.IconOnly
91 visible: root.dialog.showCloseButton
92
93 onClicked: root.dialog.reject()
94 }
95}
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Mar 28 2025 11:50:27 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.