Qt for HarmonyOS/qtohosextras doc/Context Menu on Long Press Example
< 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: