CopperSpice API
1.9.2
|
Provides a menu widget for use in menu bars, context menus, and other popup menus. More...
Public Signals | |
void | aboutToHide () |
void | aboutToShow () |
void | hovered (QAction *action) |
void | triggered (QAction *action) |
Public Signals inherited from QWidget | |
void | customContextMenuRequested (const QPoint &pos) |
void | windowIconChanged (const QIcon &icon) |
void | windowIconTextChanged (const QString &iconText) |
void | windowTitleChanged (const QString &title) |
Public Signals inherited from QObject | |
void | destroyed (QObject *obj=nullptr) |
void | objectNameChanged (const QString &objectName) |
Public Methods | |
QMenu (const QString &title, QWidget *parent=nullptr) | |
QMenu (QWidget *parent=nullptr) | |
~QMenu () | |
QAction * | actionAt (const QPoint &point) const |
QRect | actionGeometry (QAction *action) const |
QAction * | activeAction () const |
QAction * | addAction (const QIcon &icon, const QString &text) |
QAction * | addAction (const QIcon &icon, const QString &text, const QObject *receiver, const QString &member, const QKeySequence &shortcut=0) |
template<typename Func1 > | |
QAction * | addAction (const QIcon &icon, const QString &text, Func1 slot, const QKeySequence &shortcut=QKeySequence ()) |
QAction * | addAction (const QString &text) |
QAction * | addAction (const QString &text, const QObject *receiver, const QString &member, const QKeySequence &shortcut=QKeySequence ()) |
void | addAction (QAction *action) |
QMenu * | addMenu (const QIcon &icon, const QString &title) |
QMenu * | addMenu (const QString &title) |
QAction * | addMenu (QMenu *menu) |
QAction * | addSection (const QIcon &icon, const QString &text) |
QAction * | addSection (const QString &text) |
QAction * | addSeparator () |
void | clear () |
QAction * | defaultAction () const |
QAction * | exec () |
QAction * | exec (const QPoint &point, QAction *action=nullptr) |
void | hideTearOffMenu () |
QIcon | icon () const |
QAction * | insertMenu (QAction *action, QMenu *menu) |
QAction * | insertSection (QAction *location, const QIcon &icon, const QString &text) |
QAction * | insertSection (QAction *location, const QString &text) |
QAction * | insertSeparator (QAction *action) |
bool | isEmpty () const |
bool | isTearOffEnabled () const |
bool | isTearOffMenuVisible () const |
QAction * | menuAction () const |
void | popup (const QPoint &point, QAction *action=nullptr) |
bool | separatorsCollapsible () const |
void | setActiveAction (QAction *action) |
void | setAsDockMenu () |
void | setDefaultAction (QAction *action) |
void | setIcon (const QIcon &icon) |
void | setSeparatorsCollapsible (bool collapse) |
void | setTearOffEnabled (bool enabled) |
void | setTitle (const QString &title) |
void | setToolTipsVisible (bool visible) |
QSize | sizeHint () const override |
QString | title () const |
NSMenu * | toNSMenu () |
bool | toolTipsVisible () const |
Public Methods inherited from QWidget | |
QWidget (QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::EmptyFlag) | |
~QWidget () | |
bool | acceptDrops () const |
QString | accessibleDescription () const |
QString | accessibleName () const |
QList< QAction * > | actions () const |
void | activateWindow () |
void | addAction (QAction *action) |
void | addActions (const QList< QAction * > &actions) |
void | adjustSize () |
bool | autoFillBackground () const |
QPalette::ColorRole | backgroundRole () const |
QBackingStore * | backingStore () const |
QSize | baseSize () const |
QWidget * | childAt (const QPoint &position) const |
QWidget * | childAt (int x, int y) const |
QRect | childrenRect () const |
QRegion | childrenRegion () const |
void | clearFocus () |
void | clearMask () |
QMargins | contentsMargins () const |
QRect | contentsRect () const |
Qt::ContextMenuPolicy | contextMenuPolicy () const |
QCursor | cursor () const |
WId | effectiveWinId () const |
void | ensurePolished () const |
Qt::FocusPolicy | focusPolicy () const |
QWidget * | focusProxy () const |
QWidget * | focusWidget () const |
const QFont & | font () const |
QFontInfo | fontInfo () const |
QFontMetrics | fontMetrics () const |
QPalette::ColorRole | foregroundRole () const |
QRect | frameGeometry () const |
QSize | frameSize () const |
const QRect & | geometry () const |
void | getContentsMargins (int *left, int *top, int *right, int *bottom) const |
QPixmap | grab (const QRect &rectangle=QRect (QPoint (0, 0), QSize (-1,-1))) |
void | grabGesture (Qt::GestureType gestureType, Qt::GestureFlags flags=Qt::GestureFlags ()) |
void | grabKeyboard () |
void | grabMouse () |
void | grabMouse (const QCursor &cursor) |
int | grabShortcut (const QKeySequence &key, Qt::ShortcutContext context=Qt::WindowShortcut) |
QGraphicsEffect * | graphicsEffect () const |
QGraphicsProxyWidget * | graphicsProxyWidget () const |
bool | hasEditFocus () const |
bool | hasFocus () const |
virtual bool | hasHeightForWidth () const |
bool | hasMouseTracking () const |
int | height () const |
virtual int | heightForWidth (int width) const |
Qt::InputMethodHints | inputMethodHints () const |
virtual QVariant | inputMethodQuery (Qt::InputMethodQuery query) const |
void | insertAction (QAction *before, QAction *action) |
void | insertActions (QAction *before, QList< QAction * > actions) |
bool | isActiveWindow () const |
bool | isAncestorOf (const QWidget *child) const |
bool | isEnabled () const |
bool | isEnabledTo (const QWidget *parent) const |
bool | isEnabledToTLW () const |
bool | isFullScreen () const |
bool | isHidden () const |
bool | isMaximized () const |
bool | isMinimized () const |
bool | isModal () const |
bool | isTopLevel () const |
bool | isVisible () const |
bool | isVisibleTo (const QWidget *parent) const |
bool | isWindow () const |
bool | isWindowModified () const |
QLayout * | layout () const |
Qt::LayoutDirection | layoutDirection () const |
QLocale | locale () const |
QPoint | mapFrom (const QWidget *parent, const QPoint &pos) const |
QPoint | mapFromGlobal (const QPoint &pos) const |
QPoint | mapFromParent (const QPoint &pos) const |
QPoint | mapTo (const QWidget *parent, const QPoint &pos) const |
QPoint | mapToGlobal (const QPoint &pos) const |
QPoint | mapToParent (const QPoint &pos) const |
QRegion | mask () const |
int | maximumHeight () const |
QSize | maximumSize () const |
int | maximumWidth () const |
int | minimumHeight () const |
QSize | minimumSize () const |
virtual QSize | minimumSizeHint () const |
int | minimumWidth () const |
void | move (const QPoint &point) |
void | move (int x, int y) |
QWidget * | nativeParentWidget () const |
QWidget * | nextInFocusChain () const |
QRect | normalGeometry () const |
void | overrideWindowFlags (Qt::WindowFlags flags) |
QPaintEngine * | paintEngine () const override |
const QPalette & | palette () const |
QWidget * | parentWidget () const |
QPoint | pos () const |
QWidget * | previousInFocusChain () const |
QRect | rect () const |
void | releaseKeyboard () |
void | releaseMouse () |
void | releaseShortcut (int id) |
void | removeAction (QAction *action) |
void | render (QPaintDevice *target, const QPoint &targetOffset=QPoint (), const QRegion &sourceRegion=QRegion (), RenderFlags renderFlags=RenderFlags (DrawWindowBackground|DrawChildren)) |
void | render (QPainter *painter, const QPoint &targetOffset=QPoint (), const QRegion &sourceRegion=QRegion (), RenderFlags renderFlags=RenderFlags (DrawWindowBackground|DrawChildren)) |
void | repaint (const QRect &rect) |
void | repaint (const QRegion ®ion) |
void | repaint (int x, int y, int w, int h) |
void | resize (const QSize &size) |
void | resize (int w, int h) |
bool | restoreGeometry (const QByteArray &geometry) |
QByteArray | saveGeometry () const |
void | scroll (int dx, int dy) |
void | scroll (int dx, int dy, const QRect &rect) |
void | setAcceptDrops (bool on) |
void | setAccessibleDescription (const QString &description) |
void | setAccessibleName (const QString &name) |
void | setAttribute (Qt::WidgetAttribute attribute, bool enable=true) |
void | setAutoFillBackground (bool enable) |
void | setBackgroundRole (QPalette::ColorRole role) |
void | setBaseSize (const QSize &size) |
void | setBaseSize (int basew, int baseh) |
void | setContentsMargins (const QMargins &margins) |
void | setContentsMargins (int left, int top, int right, int bottom) |
void | setContextMenuPolicy (Qt::ContextMenuPolicy policy) |
void | setCursor (const QCursor &cursor) |
void | setEditFocus (bool enable) |
void | setFixedHeight (int h) |
void | setFixedSize (const QSize &size) |
void | setFixedSize (int w, int h) |
void | setFixedWidth (int w) |
void | setFocus (Qt::FocusReason reason) |
void | setFocusPolicy (Qt::FocusPolicy policy) |
void | setFocusProxy (QWidget *widget) |
void | setFont (const QFont &font) |
void | setForegroundRole (QPalette::ColorRole role) |
void | setGeometry (const QRect &rect) |
void | setGeometry (int x, int y, int w, int h) |
void | setGraphicsEffect (QGraphicsEffect *effect) |
void | setInputMethodHints (Qt::InputMethodHints hints) |
void | setLayout (QLayout *layout) |
void | setLayoutDirection (Qt::LayoutDirection direction) |
void | setLocale (const QLocale &locale) |
void | setMask (const QBitmap &bitmap) |
void | setMask (const QRegion ®ion) |
void | setMaximumHeight (int maxh) |
void | setMaximumSize (const QSize &size) |
void | setMaximumSize (int maxw, int maxh) |
void | setMaximumWidth (int maxw) |
void | setMinimumHeight (int minh) |
void | setMinimumSize (const QSize &size) |
void | setMinimumSize (int minw, int minh) |
void | setMinimumWidth (int minw) |
void | setMouseTracking (bool enable) |
void | setPalette (const QPalette &palette) |
void | setParent (QWidget *parent) |
void | setParent (QWidget *parent, Qt::WindowFlags flags) |
void | setShortcutAutoRepeat (int id, bool enable=true) |
void | setShortcutEnabled (int id, bool enable=true) |
void | setSizeIncrement (const QSize &size) |
void | setSizeIncrement (int w, int h) |
void | setSizePolicy (QSizePolicy policy) |
void | setSizePolicy (QSizePolicy::Policy horizontal, QSizePolicy::Policy vertical) |
void | setStatusTip (const QString &data) |
void | setStyle (QStyle *style) |
void | setToolTip (const QString &data) |
void | setToolTipDuration (int msec) |
void | setUpdatesEnabled (bool enable) |
void | setWhatsThis (const QString &str) |
void | setWindowFilePath (const QString &filePath) |
void | setWindowFlags (Qt::WindowFlags flags) |
void | setWindowIcon (const QIcon &icon) |
void | setWindowModality (Qt::WindowModality windowModality) |
void | setWindowOpacity (qreal level) |
void | setWindowRole (const QString &role) |
void | setWindowState (Qt::WindowStates windowState) |
QSize | size () const |
QSize | sizeIncrement () const |
QSizePolicy | sizePolicy () const |
void | stackUnder (QWidget *widget) |
QString | statusTip () const |
QStyle * | style () const |
QString | styleSheet () const |
bool | testAttribute (Qt::WidgetAttribute attribute) const |
QString | toolTip () const |
int | toolTipDuration () const |
QWidget * | topLevelWidget () const |
bool | underMouse () const |
void | ungrabGesture (Qt::GestureType gestureType) |
void | unsetCursor () |
void | unsetLayoutDirection () |
void | unsetLocale () |
void | update (const QRect &rect) |
void | update (const QRegion ®ion) |
void | update (int x, int y, int w, int h) |
void | updateGeometry () |
bool | updatesEnabled () const |
QRegion | visibleRegion () const |
QString | whatsThis () const |
int | width () const |
QWidget * | window () const |
QString | windowFilePath () const |
Qt::WindowFlags | windowFlags () const |
QWindow * | windowHandle () const |
QIcon | windowIcon () const |
Qt::WindowModality | windowModality () const |
qreal | windowOpacity () const |
QString | windowRole () const |
Qt::WindowStates | windowState () const |
QString | windowTitle () const |
Qt::WindowType | windowType () const |
WId | winId () const |
int | x () const |
int | y () const |
Public Methods inherited from QObject | |
QObject (QObject *parent=nullptr) | |
~QObject () | |
bool | blockSignals (bool block) |
const QList< QObject * > & | children () const |
bool | connect (const QObject *sender, const QString &signalMethod, const QString &location, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection) |
bool | connect (const QObject *sender, const QString &signalMethod, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection) |
bool | disconnect (const QObject *receiver, const QString &slotMethod=QString ()) const |
bool | disconnect (const QString &signalMethod, const QString &location, const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const |
bool | disconnect (const QString &signalMethod=QString (), const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const |
void | dumpObjectInfo () |
void | dumpObjectTree () |
QList< QString > | dynamicPropertyNames () const |
virtual bool | event (QEvent *event) |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
template<typename T > | |
T | findChild (const QString &childName=QString ()) const |
template<class T > | |
QList< T > | findChildren (const QRegularExpression ®Exp, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
template<class T > | |
QList< T > | findChildren (const QString &childName=QString (), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
bool | inherits (const QString &className) const |
void | installEventFilter (QObject *filterObj) |
bool | isWidgetType () const |
bool | isWindowType () const |
void | killTimer (int id) |
const QMetaObject * | metaObject () const |
void | moveToThread (QThread *targetThread) |
QString | objectName () const |
QObject * | parent () const |
template<class T = QVariant> | |
T | property (const QString &name) const |
void | removeEventFilter (QObject *obj) |
void | setObjectName (const QString &name) |
void | setParent (QObject *parent) |
bool | setProperty (const QString &name, const QVariant &value) |
bool | signalsBlocked () const |
int | startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer) |
QThread * | thread () const |
Public Methods inherited from QPaintDevice | |
virtual | ~QPaintDevice () |
int | colorCount () const |
int | depth () const |
int | devicePixelRatio () const |
qreal | devicePixelRatioF () const |
int | height () const |
int | heightMM () const |
int | logicalDpiX () const |
int | logicalDpiY () const |
bool | paintingActive () const |
int | physicalDpiX () const |
int | physicalDpiY () const |
int | width () const |
int | widthMM () const |
Static Public Methods | |
static QAction * | exec (const QList< QAction * > &actionList, const QPoint &point, QAction *action=nullptr, QWidget *parent=nullptr) |
Static Public Methods inherited from QWidget | |
static QWidget * | createWindowContainer (QWindow *window, QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::EmptyFlag) |
static QWidget * | find (WId id) |
static QWidget * | keyboardGrabber () |
static QWidget * | mouseGrabber () |
static void | setTabOrder (QWidget *firstWidget, QWidget *secondWidget) |
Static Public Methods inherited from QObject | |
static bool | connect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod, Qt::ConnectionType type=Qt::AutoConnection) |
static bool | connect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection, const QString &location=QString ()) |
static bool | connect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn > | |
static bool | connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...), Qt::ConnectionType type=Qt::AutoConnection) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T > | |
static bool | connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotLambda, Qt::ConnectionType type=Qt::AutoConnection) |
static bool | disconnect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod) |
static bool | disconnect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod) |
static bool | disconnect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod) |
static bool | disconnect (const QObject *sender, std::nullptr_t, const QObject *receiver, std::nullptr_t) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn > | |
static bool | disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...)) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver > | |
static bool | disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, std::nullptr_t slotMethod=nullptr) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T > | |
static bool | disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotMethod) |
static QMetaObject & | staticMetaObject () |
static QString | tr (const char *text, const char *comment=nullptr, std::optional< int > numArg=std::optional< int >()) |
Protected Methods | |
void | actionEvent (QActionEvent *event) override |
void | changeEvent (QEvent *event) override |
int | columnCount () const |
void | enterEvent (QEvent *event) override |
bool | event (QEvent *event) override |
bool | focusNextPrevChild (bool next) override |
void | hideEvent (QHideEvent *event) override |
void | initStyleOption (QStyleOptionMenuItem *option, const QAction *action) const |
void | keyPressEvent (QKeyEvent *event) override |
void | leaveEvent (QEvent *event) override |
void | mouseMoveEvent (QMouseEvent *event) override |
void | mousePressEvent (QMouseEvent *event) override |
void | mouseReleaseEvent (QMouseEvent *event) override |
void | paintEvent (QPaintEvent *event) override |
void | timerEvent (QTimerEvent *event) override |
void | wheelEvent (QWheelEvent *event) override |
Protected Methods inherited from QWidget | |
virtual void | closeEvent (QCloseEvent *event) |
virtual void | contextMenuEvent (QContextMenuEvent *event) |
void | create (WId window=0, bool initializeWindow=true, bool destroyOldWindow=true) |
void | destroy (bool destroyWindow=true, bool destroySubWindows=true) |
virtual void | dragEnterEvent (QDragEnterEvent *event) |
virtual void | dragLeaveEvent (QDragLeaveEvent *event) |
virtual void | dragMoveEvent (QDragMoveEvent *event) |
virtual void | dropEvent (QDropEvent *event) |
bool | event (QEvent *event) override |
virtual void | focusInEvent (QFocusEvent *event) |
bool | focusNextChild () |
virtual void | focusOutEvent (QFocusEvent *event) |
bool | focusPreviousChild () |
void | initPainter (QPainter *painter) const override |
virtual void | inputMethodEvent (QInputMethodEvent *event) |
virtual void | keyReleaseEvent (QKeyEvent *event) |
int | metric (PaintDeviceMetric metric) const override |
virtual void | mouseDoubleClickEvent (QMouseEvent *event) |
virtual void | moveEvent (QMoveEvent *event) |
virtual bool | nativeEvent (const QByteArray &eventType, void *message, long *result) |
virtual void | resizeEvent (QResizeEvent *event) |
virtual void | showEvent (QShowEvent *event) |
virtual void | tabletEvent (QTabletEvent *event) |
Protected Methods inherited from QObject | |
virtual void | childEvent (QChildEvent *event) |
virtual void | connectNotify (const QMetaMethod &signalMethod) const |
virtual void | customEvent (QEvent *event) |
virtual void | disconnectNotify (const QMetaMethod &signalMethod) const |
bool | isSignalConnected (const QMetaMethod &signalMethod) const |
int | receivers (const QString &signal) const |
QObject * | sender () const |
int | senderSignalIndex () const |
virtual void | timerEvent (QTimerEvent *event) |
Protected Methods inherited from QPaintDevice | |
QPaintDevice () | |
Friends | |
class | QAction |
class | QComboBox |
class | QMenuBar |
Additional Inherited Members | |
Public Typedefs inherited from QWidget | |
using | RenderFlags = QFlags< RenderFlag > |
Public Types inherited from QWidget | |
enum | RenderFlag |
Public Types inherited from QPaintDevice | |
enum | PaintDeviceMetric |
Public Slots inherited from QWidget | |
bool | close () |
void | hide () |
void | lower () |
void | raise () |
void | repaint () |
void | setDisabled (bool disable) |
void | setEnabled (bool enable) |
void | setFocus () |
void | setHidden (bool hidden) |
void | setStyleSheet (const QString &styleSheet) |
virtual void | setVisible (bool visible) |
void | setWindowModified (bool modified) |
void | setWindowTitle (const QString &title) |
void | show () |
void | showFullScreen () |
void | showMaximized () |
void | showMinimized () |
void | showNormal () |
void | update () |
Public Slots inherited from QObject | |
void | deleteLater () |
Protected Slots inherited from QWidget | |
void | updateMicroFocus () |
Related Functions inherited from QWidget | |
QWidgetList | |
WId | |
Related Functions inherited from QObject | |
T | qobject_cast (QObject *object) |
QObjectList | |
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus.
A menu widget is a selection menu. It can be either a pull-down menu in a menu bar or a standalone context menu. Pull-down menus are shown by the menu bar when the user clicks on the respective item or presses the specified shortcut key. Use QMenuBar::addMenu() to insert a menu into a menu bar. Context menus are usually invoked by some special keyboard key or by right-clicking. They can be executed either asynchronously with popup() or synchronously with exec(). Menus can also be invoked in response to button presses; these are just like context menus except for how they are invoked.
Windows XP widget style | Mac OS X widget style | Fusion widget style |
A menu consists of a list of action items. Actions are added with the addAction(), addActions() and insertAction() methods. An action is represented vertically and rendered by QStyle. In addition, actions can have a text label, an optional icon drawn on the very left side, and shortcut key sequence such as "Ctrl+X".
The existing actions held by a menu can be found with actions().
There are four kinds of action items: separators, actions that show a submenu, widgets, and actions that perform an action. Separators are inserted with addSeparator(), submenus with addMenu(), and all other items are considered action items.
When inserting action items you usually specify a receiver and a slot. The receiver will be notified whenever the item is triggered(). In addition, QMenu provides two signals, activated() and highlighted(), which signal the QAction that was triggered from the menu.
You clear a menu with clear() and remove individual action items with removeAction().
A QMenu can also provide a tear-off menu. A tear-off menu is a top-level window that contains a copy of the menu. This makes it possible for the user to "tear off" frequently used menus and position them in a convenient place on the screen. If you want this functionality for a particular menu, insert a tear-off handle with setTearOffEnabled(). When using tear-off menus, bear in mind that the concept is not typically used on Microsoft Windows so some users may not be familiar with it. Consider using a QToolBar instead.
Widgets can be inserted into menus with the QWidgetAction class. Instances of this class are used to hold widgets, and are inserted into menus with the addAction() overload that takes a QAction.
Conversely, actions can be added to widgets with the addAction(), addActions() and insertAction() methods.
A given QMenu can be inserted only once in a menu or menubar. Subsequent insertions will have no effect or will result in a disabled menu item.
|
explicit |
Constructs a menu with the given parent. Although a popup menu is always a top-level widget, if a parent is passed the popup menu will be deleted when that parent is destroyed.
Constructs a menu with a title and the given parent. Although a popup menu is always a top-level widget, if a parent is passed the popup menu will be deleted when that parent is destroyed.
QMenu::~QMenu | ( | ) |
Destroys the menu.
|
signal |
This signal is emitted just before the menu is hidden from the user.
|
signal |
This signal is emitted just before the menu is shown to the user.
Returns the item at point. Returns a nullptr if there is no item there.
|
overrideprotectedvirtual |
Reimplemented from QWidget::actionEvent()
QAction * QMenu::activeAction | ( | ) | const |
Returns the currently highlighted action or a nullptr if no action is currently highlighted.
Creates a new action with an icon and some text. The method adds the new action to the menu and returns a pointer to the new QAction.
QAction * QMenu::addAction | ( | const QIcon & | icon, |
const QString & | text, | ||
const QObject * | receiver, | ||
const QString & | member, | ||
const QKeySequence & | shortcut = 0 |
||
) |
Creates a new action with an icon and some text and an optional shortcut. The action's triggered() signal is connected to the member slot of the receiver object. The method adds the newly created action to the menu's list of actions and returns a pointer to the new QAction.
|
inline |
Creates a new action with the given text and an optional shortcut. The action's triggered() signal is connected to the slot parameter. This method adds the new action to the menu and returns a pointer to the new action.
QMenu takes ownership of the returned QAction.
Creates a new action with text. The method adds the new action to the menu and returns a pointer to the new QAction.
QAction * QMenu::addAction | ( | const QString & | text, |
const QObject * | receiver, | ||
const QString & | member, | ||
const QKeySequence & | shortcut = QKeySequence() |
||
) |
Creates a new action with the given text and an optional shortcut. The action's triggered() signal is connected to the receivers member slot. The method adds the newly created action to the menu and returns a pointer to the new QAction.
|
using |
Appends action to the list of existing actions available for this widget. A QAction list is typically used to create a context QMenu, however it can be represented in different ways depending on the widget.
A QWidget should only have one of each action. Adding an action which already exists will not cause the same action to be in the widget multiple times. The ownership of action is not transferred to this QWidget.
Appends a new QMenu with icon and title to the menu. The current QMenu takes ownership of the new menu. Returns a pointer to the new menu.
QMenu * QMenu::addMenu | ( | const QString & | title | ) |
Appends a new QMenu with title to the menu. The current QMenu takes ownership of the new menu. Returns a pointer to the new menu.
QAction * QMenu::addMenu | ( | QMenu * | menu | ) |
Adds menu as a submenu to the current menu. Returns a pointer to the menuAction. This menu does not take ownership of menu.
Creates a new action then calls QAction::setSeparator() and passes true. The hint for this action is set to the given text and icon. This method adds the new action to the menu and returns a pointer to the new action.
The rendering of the text hint is style and platform dependent. Widget styles can use the text information in the rendering for sections or choose to ignore it and render sections like simple separators.
QMenu takes ownership of the returned QAction.
Creates a new action then calls QAction::setSeparator() and passes true. The hint for this action is set to the given text. This method adds the new action to the menu and returns a pointer to the new action.
The rendering of the text hint is style and platform dependent. Widget styles can use the text information in the rendering for sections or choose to ignore it and render sections like simple separators.
QMenu takes ownership of the returned QAction.
QAction * QMenu::addSeparator | ( | ) |
This method creates a new separator action, i.e. an action with QAction::isSeparator() returning true, and adds the new action to this menu's list of actions. It returns the newly created action.
|
overrideprotectedvirtual |
Reimplemented from QWidget::changeEvent()
void QMenu::clear | ( | ) |
Removes all the menu's actions. Actions owned by the menu and not shown in any other widget are deleted.
|
protected |
If a menu does not fit on the screen it lays itself out so that it does fit. It is style dependent what layout means (for example, on Windows it will use multiple columns). This method returns the number of columns necessary.
QAction * QMenu::defaultAction | ( | ) | const |
Returns the current default action.
|
overrideprotectedvirtual |
Reimplemented from QWidget::enterEvent()
|
overrideprotected |
Reimplemented from QWidget::event()
QAction * QMenu::exec | ( | ) |
Shows the current menu and waits for the user to select an item. Returns the triggered QAction in either the popup menu or one of its submenus, or a nullptr if no item was triggered (normally because the user pressed Esc).
Calling this method is equivalent to exec(pos())
.
|
static |
Shows the current menu and waits for the user to select an item. Returns the triggered QAction in either the popup menu or one of its submenus, or a nullptr if no item was triggered (normally because the user pressed Esc).
The menu's actions are specified by the actionList. If you specify an action, then that action will appear at global position point. If no action is not specified then the top left corner of the menu appears at position point. The parent is the menu's parent widget. Specifying the parent will provide context when pos alone is not enough to decide where the menu should go. This can occur with multiple desktops or when the parent is embedded in QGraphicsView.
Shows the current menu and waits for the user to select an item. Returns the triggered QAction in either the popup menu or one of its submenus, or a nullptr if no item was triggered (normally because the user pressed Esc).
Pops up the menu so the action will be at the specified point. To translate a widget's local coordinates into global coordinates, use QWidget::mapToGlobal(). All signals are emitted as usual. If you connect a QAction to a slot and call QMenu::exec(), the result will be available in the slot and also in the return value of exec().
A common use case is to position the menu at the current mouse position.
This code will align the menu to "somewidget".
The following code will display the menu at the coordinates where the mouse was clicked.
When positioning a menu with exec() or popup(), bear in mind that you can not rely on the menu's current size(). For performance reasons, the menu adapts its size only when necessary. So in many cases, the size before and after the show is different. Instead, use sizeHint() which calculates the proper size depending on the menu's current contents.
|
overrideprotectedvirtual |
Reimplemented from QWidget::focusNextPrevChild()
|
overrideprotectedvirtual |
Reimplemented from QWidget::hideEvent()
void QMenu::hideTearOffMenu | ( | ) |
This method will hide the torn off menu making it disappear from the users desktop.
|
signal |
This signal is emitted when a menu action is highlighted, action is the action that caused the signal to be emitted. This is used to update status information.
QIcon QMenu::icon | ( | ) | const |
Returns the value of the property.
|
protected |
Initialize option with the values from this menu and information from action. This method is useful for subclasses when they need a QStyleOptionMenuItem, but do not want to fill in all the information themselves.
This method inserts menu before action. Returns the result of calling QMenu::menuAction().
Creates a new action then calls QAction::setSeparator() and passes true. The hint for this action is set to the given text and icon. This method inserts the new action at the given location in the menu and returns a pointer to the new action.
The rendering of the text hint is style and platform dependent. Widget styles can use the text information in the rendering for sections or choose to ignore it and render sections like simple separators.
QMenu takes ownership of the returned QAction.
Creates a new action then calls QAction::setSeparator() and passes true. The hint for this action is set to the given text. This method inserts the new action at the given location in the menu and returns a pointer to the new action.
The rendering of the text hint is style and platform dependent. Widget styles can use the text information in the rendering for sections or choose to ignore it and render sections like simple separators.
QMenu takes ownership of the returned QAction.
This method creates a new separator action and inserts it before the action. Returns a pointer to the new action.
bool QMenu::isEmpty | ( | ) | const |
Returns true if there are no visible actions inserted into the menu, false otherwise.
bool QMenu::isTearOffEnabled | ( | ) | const |
Returns the value of the property.
bool QMenu::isTearOffMenuVisible | ( | ) | const |
When a menu is torn off a second menu is shown to display the menu contents in a new window. When the menu is in this mode and the menu is visible returns true, otherwise false.
|
overrideprotectedvirtual |
Reimplemented from QWidget::keyPressEvent()
|
overrideprotectedvirtual |
Reimplemented from QWidget::leaveEvent()
QAction * QMenu::menuAction | ( | ) | const |
Returns the action associated with this menu.
|
overrideprotectedvirtual |
Reimplemented from QWidget::mouseMoveEvent()
|
overrideprotectedvirtual |
Reimplemented from QWidget::mousePressEvent()
|
overrideprotectedvirtual |
Reimplemented from QWidget::mouseReleaseEvent()
|
overrideprotectedvirtual |
Reimplemented from QWidget::paintEvent()
Displays the menu with the action at the specified point. To translate a widget's local coordinates into global coordinates use QWidget::mapToGlobal(). When specifying a position for a menu using exec() or popup(), do not calculate the position based on the menu's current size(). Instead use sizeHint() which calculates the proper size depending on the menu's current contents.
bool QMenu::separatorsCollapsible | ( | ) | const |
Returns the value of the property.
void QMenu::setActiveAction | ( | QAction * | action | ) |
Sets the currently highlighted action to action.
void QMenu::setAsDockMenu | ( | ) |
Set this menu as the dock menu. Available on Mac OS X only.
void QMenu::setDefaultAction | ( | QAction * | action | ) |
This sets the default action to action. The default action may have a visual cue, depending on the current QStyle. A default action usually indicates what will happen by default when a drop occurs.
void QMenu::setIcon | ( | const QIcon & | icon | ) |
Sets the value of the property to icon.
void QMenu::setSeparatorsCollapsible | ( | bool | collapse | ) |
Sets the value of the property to collapse.
void QMenu::setTearOffEnabled | ( | bool | enabled | ) |
Sets the value of the property to enabled.
void QMenu::setTitle | ( | const QString & | title | ) |
Sets the value of the property to title.
void QMenu::setToolTipsVisible | ( | bool | visible | ) |
Sets the value of the property to visible.
|
overridevirtual |
Reimplemented from QWidget::sizeHint()
|
overrideprotected |
Reimplemented from QObject::timerEvent()
QString QMenu::title | ( | ) | const |
Returns the value of the property.
NSMenu * QMenu::toNSMenu | ( | ) |
Returns the native NSMenu for this menu. Available on Mac OS X only.
bool QMenu::toolTipsVisible | ( | ) | const |
Returns the value of the property.
|
signal |
This signal is emitted when an action in this menu is triggered. The action is the action that caused the signal to be emitted.
Normally, you connect each menu action's triggered() signal to its own custom slot, but sometimes you will want to connect several actions to a single slot, for example, when you have a group of closely related actions, such as "left justify", "center", "right justify".
|
overrideprotectedvirtual |
Reimplemented from QWidget::wheelEvent()
|
This property holds the icon of the menu. This is equivalent to the QAction::icon property of the menuAction().
By default, if no icon is explicitly set, this property contains a null icon.
Properties | Class Methods |
---|---|
read | icon |
write | setIcon |
|
This property holds whether consecutive separators should be collapsed. This property specifies whether consecutive separators in the menu should be visually collapsed to a single one. Separators at the beginning or the end of the menu are also hidden. By default this property is true.
Properties | Class Methods |
---|---|
read | separatorsCollapsible |
write | setSeparatorsCollapsible |
|
This property holds whether the menu supports being torn off. When true, the menu contains a special tear-off item (often shown as a dashed line at the top of the menu) that creates a copy of the menu when it is triggered.
This "torn-off" copy lives in a separate window. It contains the same menu items as the original menu, with the exception of the tear-off handle.
By default, this property is false.
Properties | Class Methods |
---|---|
read | isTearOffEnabled |
write | setTearOffEnabled |
|
This property holds the title of the menu. This is equivalent to the QAction::text property of the menuAction().
By default, this property contains an empty string.
Properties | Class Methods |
---|---|
read | title |
write | setTitle |
|
This property specifies whether action menu entries show their tooltip.
By default this property is false.
Properties | Class Methods |
---|---|
read | toolTipsVisible |
write | setToolTipsVisible |