Jump to content

Qt for HarmonyOS/qtohosextras doc/Context Menu on Long Press Example

From Qt Wiki
Revision as of 09:05, 16 September 2026 by Shawn Luo (talk | contribs) (Add example documentation from qdoc output (QTFOROH-2307))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

< Qt for HarmonyOS / qtohosextras doc

Context Menu on Long Press Example

Demonstrates enabling synthesized context-menu events for long-press touch input.


The example calls QOhosAppContext::enableContextMenuEventOnLongPress() right after constructing the application, before any window is created. The main window contains a button that overrides QWidget::contextMenuEvent() and logs the reason of every context menu event it receives. A long press on the button produces a context menu event whose reason is QContextMenuEvent::Other.

Note: enableContextMenuEventOnLongPress() has to be called before the event loop starts and takes effect for the whole application lifetime. Handlers that filter on QContextMenuEvent::reason() must accept Other in addition to Mouse to react to long presses.

Files: