Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquickmenu.cpp File Reference

(7ca76d3799b4081f64c4dc2877b52dcc4d03e828)

#include "qquickmenu_p.h"
#include "qquickmenu_p_p.h"
#include "qquickmenuitem_p_p.h"
#include <private/qtquicktemplates2-config_p.h>
#include "qquickmenuseparator_p.h"
#include "qquicknativemenuitem_p.h"
#include "qquickoverlay_p.h"
#include "qquickoverlay_p_p.h"
#include "qquickpopupitem_p_p.h"
#include "qquickpopuppositioner_p_p.h"
#include "qquickaction_p.h"
#include <QtCore/qloggingcategory.h>
#include <QtGui/qevent.h>
#include <QtGui/qcursor.h>
#include <QtGui/qpa/qplatformintegration.h>
#include <QtGui/qpa/qplatformtheme.h>
#include <QtGui/private/qhighdpiscaling_p.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/qquickitemview_p_p.h>
#include <QtQuick/private/qquickevents_p_p.h>
#include <QtQuick/private/qquicklistview_p.h>
#include <QtQuick/private/qquickrendercontrol_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 ()
QString nativeMenuItemListToString (const QList< QQuickNativeMenuItem * > &nativeItems)
static QWindoweffectiveWindow (QWindow *window, QPoint *offset)
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

◆ effectiveWindow()

QWindow * effectiveWindow ( QWindow * window,
QPoint * offset )
static

Definition at line 527 of file qquickmenu.cpp.

◆ findParentMenuItem()

QQuickItem * findParentMenuItem ( QQuickMenu * subMenu)
static

Definition at line 1180 of file qquickmenu.cpp.

◆ nativeMenuItemListToString()

QString nativeMenuItemListToString ( const QList< QQuickNativeMenuItem * > & nativeItems)

Definition at line 427 of file qquickmenu.cpp.

◆ shouldCascade()

bool shouldCascade ( )
static

Definition at line 269 of file qquickmenu.cpp.

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

! \nativetype QQuickMenu \inqmlmodule QtQuick.Controls

Since
5.7

\table \row

  • \caption Native macOS menu.
  • \caption Non-native \l {Material Style}{Material style} menu. \endtable

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

For context menus, see \l {Context Menus}.

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.

Button {
id: fileButton
text: "File"
onClicked: menu.open()
Menu {
id: menu
y: fileButton.height
MenuItem {
text: "New..."
}
MenuItem {
text: "Open..."
}
MenuItem {
text: "Save"
}
}
}

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

onClicked: menu.visible = !menu.visible
Menu {
id: menu
// ...
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent

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" }
}
}

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 267 of file qquickmenu.cpp.

◆ SUBMENU_DELAY

QT_BEGIN_NAMESPACE const int SUBMENU_DELAY = 225
static

Definition at line 52 of file qquickmenu.cpp.