QContextMenuEvent Class▲
-
Header: QContextMenuEvent
-
CMake:
find_package(Qt6 REQUIRED COMPONENTS Gui)
target_link_libraries(mytarget PRIVATE Qt6::Gui)
-
qmake: QT += gui
-
Inherits: QInputEvent
-
Group: QContextMenuEvent is part of events
Detailed Description▲
Context menu events are sent to widgets when a user performs an action associated with opening a context menu. The actions required to open context menus vary between platforms; for example, on Windows, pressing the menu button or clicking the right mouse button will cause this event to be sent.
When this event occurs it is customary to show a QMenu with a context menu, if this is relevant to the context.
Member Type Documentation▲
enum QContextMenuEvent::Reason▲
This enum describes the reason why the event was sent.
Constant |
Value |
Description |
---|---|---|
QContextMenuEvent::Mouse |
0 |
The mouse caused the event to be sent. Normally this means the right mouse button was clicked, but this is platform dependent. |
QContextMenuEvent::Keyboard |
1 |
The keyboard caused this event to be sent. On Windows, this means the menu button was pressed. |
QContextMenuEvent::Other |
2 |
The event was sent by some other means (i.e. not by the mouse or keyboard). |
Member Function Documentation▲
QContextMenuEvent::QContextMenuEvent(QContextMenuEvent::Reason reason, const QPoint &pos, const QPoint &globalPos, Qt::KeyboardModifiers modifiers = Qt::NoModifier)▲
Constructs a context menu event object with the accept parameter flag set to false.
The reason parameter must be QContextMenuEvent::Mouse or QContextMenuEvent::Keyboard.
The pos parameter specifies the mouse position relative to the receiving widget. globalPos is the mouse position in absolute coordinates. The modifiers holds the keyboard modifiers.
const QPoint &QContextMenuEvent::globalPos() const▲
Returns the global position of the mouse pointer at the time of the event.
See Also▲
int QContextMenuEvent::globalX() const▲
Returns the global x position of the mouse pointer at the time of the event.
See Also▲
int QContextMenuEvent::globalY() const▲
Returns the global y position of the mouse pointer at the time of the event.
See Also▲
const QPoint &QContextMenuEvent::pos() const▲
Returns the position of the mouse pointer relative to the widget that received the event.
See Also▲
QContextMenuEvent::Reason QContextMenuEvent::reason() const▲
Returns the reason for this context event.
int QContextMenuEvent::x() const▲
Returns the x position of the mouse pointer, relative to the widget that received the event.
See Also▲
int QContextMenuEvent::y() const▲
Obsolete Members for QContextMenuEvent▲
The following members of class QContextMenuEvent are deprecated. We strongly advise against using them in new code.
Obsolete Member Function Documentation▲
QContextMenuEvent::QContextMenuEvent(QContextMenuEvent::Reason reason, const QPoint &pos)▲
This function is deprecated since 6.4. We strongly advise against using it in new code.
Use the other constructor instead (global position is required).
Constructs a context menu event object with the accept parameter flag set to false.
The reason parameter must be QContextMenuEvent::Mouse or QContextMenuEvent::Keyboard.
The pos parameter specifies the mouse position relative to the receiving widget.
The globalPos() is initialized to QCursor::pos(), which may not be appropriate. Use the other constructor to specify the global position explicitly.