Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qquickmenu.cpp File Reference

(99c7fe45be00b694da4041c5a06e5484f2985dc6)

#include "qquickmenu_p.h"
#include "qquickmenu_p_p.h"
#include "qquickmenuitem_p_p.h"
#include <private/qtquicktemplates2-config_p.h>
#include "qquickpopupitem_p_p.h"
#include "qquickpopuppositioner_p_p.h"
#include "qquickaction_p.h"
#include <QtGui/qevent.h>
#include <QtGui/qcursor.h>
#include <QtGui/qpa/qplatformintegration.h>
#include <QtGui/private/qguiapplication_p.h>
#include <QtQml/qqmlcontext.h>
#include <QtQml/qqmlcomponent.h>
#include <QtQml/private/qqmlengine_p.h>
#include <QtQml/private/qv4scopedvalue_p.h>
#include <QtQml/private/qv4variantobject_p.h>
#include <QtQml/private/qv4qobjectwrapper_p.h>
#include <private/qqmlobjectmodel_p.h>
#include <QtQuick/private/qquickitem_p.h>
#include <QtQuick/private/qquickitemchangelistener_p.h>
#include <QtQuick/private/qquickevents_p_p.h>
#include <QtQuick/private/qquickwindow_p.h>
#include "moc_qquickmenu_p.cpp"
+ Include dependency graph for qquickmenu.cpp:

Go to the source code of this file.

Classes

class  QQuickMenuPositioner
 

Functions

static bool shouldCascade ()
 
static QQuickItemfindParentMenuItem (QQuickMenu *subMenu)
 

Variables

static QT_BEGIN_NAMESPACE const int SUBMENU_DELAY = 225
 
static const QQuickPopup::ClosePolicy cascadingSubMenuClosePolicy = QQuickPopup::CloseOnEscape | QQuickPopup::CloseOnPressOutsideParent
 Menu popup that can be used as a context menu or popup menu.
 

Function Documentation

◆ findParentMenuItem()

static QQuickItem * findParentMenuItem ( QQuickMenu * subMenu)
static

Definition at line 559 of file qquickmenu.cpp.

References QQuickMenuPrivate::get(), i, item, and menu.

Referenced by QQuickMenuPrivate::resolveParentItem().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ shouldCascade()

static bool shouldCascade ( )
static

Definition at line 205 of file qquickmenu.cpp.

References QPlatformIntegration::MultipleWindows, and QGuiApplicationPrivate::platformIntegration().

Referenced by QQuickMenuPrivate::QQuickMenuPrivate(), and QQuickMenu::resetCascade().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ cascadingSubMenuClosePolicy

const QQuickPopup::ClosePolicy cascadingSubMenuClosePolicy = QQuickPopup::CloseOnEscape | QQuickPopup::CloseOnPressOutsideParent
static

Menu popup that can be used as a context menu or popup menu.

\qmltype Menu
\inherits Popup

! \instantiates QQuickMenu \inqmlmodule QtQuick.Controls

Since
5.7

Menu has two main use cases: \list

  • Context menus; for example, a menu that is shown after right clicking
  • Popup menus; for example, a menu that is shown after clicking a button \endlist

When used as a context menu, the recommended way of opening the menu is to call \l popup(). Unless a position is explicitly specified, the menu is positioned at the mouse cursor on desktop platforms that have a mouse cursor available, and otherwise centered over its parent item.

MouseArea {
anchors.fill: parent
acceptedButtons: Qt.LeftButton | Qt.RightButton
onClicked: {
if (mouse.button === Qt.RightButton)
contextMenu.popup()
}
onPressAndHold: {
if (mouse.source === Qt.MouseEventNotSynthesized)
contextMenu.popup()
}
Menu {
id: contextMenu
MenuItem { text: "Cut" }
MenuItem { text: "Copy" }
MenuItem { text: "Paste" }
}
}
QQuickItem * fill
QString text
Definition qcompare.h:63
GLenum GLuint id
[7]
QQuickAnchors * anchors(QQuickItem *item)

When used as a popup menu, it is easiest to specify the position by specifying the desired \l {Popup::}{x} and \l {Popup::}{y} coordinates using the respective properties, and call \l {Popup::}{open()} to open the menu.

id: fileButton
text: "File"
onClicked: menu.open()
Menu {
y: fileButton.height
MenuItem {
text: "New..."
}
MenuItem {
text: "Open..."
}
MenuItem {
text: "Save"
}
}
}
int height
the height of the widget excluding any window frame
Definition qwidget.h:115
Button
GLint y
QMenu menu
[5]

If the button should also close the menu when clicked, use the Popup.CloseOnPressOutsideParent flag:

onClicked: menu.visible = !menu.visible
Menu {
// ...
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent
bool visible
whether the widget is visible
Definition qwidget.h:144

Since QtQuick.Controls 2.3 (Qt 5.10), it is also possible to create sub-menus and declare Action objects inside Menu:

Menu {
Action { text: "Cut" }
Action { text: "Copy" }
Action { text: "Paste" }
MenuSeparator { }
Menu {
title: "Find/Replace"
Action { text: "Find Next" }
Action { text: "Find Previous" }
Action { text: "Replace" }
}
}
QString title
[35]

Sub-menus are \l {cascade}{cascading} by default on desktop platforms that have a mouse cursor available. Non-cascading menus are shown one menu at a time, and centered over the parent menu.

Typically, menu items are statically declared as children of the menu, but Menu also provides API to \l {addItem}{add}, \l {insertItem}{insert}, \l {moveItem}{move} and \l {removeItem}{remove} items dynamically. The items in a menu can be accessed using \l itemAt() or \l {Popup::}{contentChildren}.

Although \l {MenuItem}{MenuItems} are most commonly used with Menu, it can contain any type of item.

Definition at line 203 of file qquickmenu.cpp.

Referenced by QQuickMenuPrivate::prepareEnterTransition().

◆ SUBMENU_DELAY

QT_BEGIN_NAMESPACE const int SUBMENU_DELAY = 225
static

Definition at line 38 of file qquickmenu.cpp.

Referenced by QQuickMenuPrivate::startHoverTimer().