MauiKit Controls

ToolButtonMenu.qml
1import QtQuick
2import QtQuick.Controls
3
4import org.mauikit.controls as Maui
5
6import "private" as Private
7
8/**
9 * @inherit QtQuick.Controls.ToolButton
10 * @since org.mauikit.controls 1.0
11 *
12 * @brief A control to host into a Menu popup, a set of MenuItem or Actions as its children.
13 *
14 * This control provides a quick way to have a menu attached to a tool button.
15 * All child items will be positioned inside a MauiKit ContextualMenu.
16 * @see ContextualMenu
17 *
18 * @image html Misc/toolbuttonmenu.png
19 *
20 * @code
21 * Maui.ToolButtonMenu
22 * {
23 * icon.name: "overflow-menu"
24 *
25 * MenuItem
26 * {
27 * text : "Menu1"
28 * }
29 *
30 * MenuItem
31 * {
32 * text : "Menu2"
33 * }
34 *
35 * MenuItem
36 * {
37 * text : "Menu3"
38 * }
39 * }
40 * @endcode
41 */
42ToolButton
43{
44 id: control
45
46 /**
47 * @brief List of items, such as MenuItem, or Action, to populate the contextual menu.
48 * This is the default property, so all the children will go into the menu.
49 * @property list<QtObject> ToolButtonMenu::content
50 */
51 default property alias content : _menu.contentData
52
53 /**
54 * @brief Alias to the actual menu component holding the menu entries.
55 * This can be modified for fine tuning the menu position or look.
56 * @property ContextualMenu ToolButtonMenu::menu
57 */
58 readonly property alias menu : _menu
59
60 indicator: Private.DropDownIndicator
61 {
62 visible: _menu.count > 0
63 item: control
64 }
65
66 focusPolicy: Qt.NoFocus
67 checked: _menu.visible
68 display: ToolButton.IconOnly
69
70 onClicked:
71 {
72 if(_menu.visible)
73 {
74 close()
75 }else
76 {
78 }
79 }
80
81 Maui.ContextualMenu
82 {
83 id: _menu
84 }
85
86 /**
87 * @brief Forces to open the contextual menu.
88 * The menu will be positioned under the button.
89 * To open the menu at a position where it has been invoked, use the `popup` function instead.
90 * @see popup
91 */
92 function open()
93 {
94 _menu.show(0, height + Maui.Style.space.medium)
95 _menu.forceActiveFocus()
96 }
97
98 /**
99 * @brief Forces to popup the contextual menu.
100 * This means the menu will be opened and positioned at the event coordinates.
101 */
102 function popup()
103 {
104 _menu.popup()
105 _menu.forceActiveFocus()
106 }
107
108 /**
109 * @brief Forces to close the contextual menu.
110 */
111 function close()
112 {
113 _menu.close()
114 }
115}
void close()
Forces to close the contextual menu.
void open()
Forces to open the contextual menu.
alias menu
Alias to the actual menu component holding the menu entries.
alias content
List of items, such as MenuItem, or Action, to populate the contextual menu.
KGuiItem open()
KGuiItem close()
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Apr 11 2025 11:50:35 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.