diff options
| author | Volodymyr Zibarov <gogan419@gmail.com> | 2024-05-03 15:58:50 +0300 |
|---|---|---|
| committer | Volodymyr Zibarov <gogan419@gmail.com> | 2024-05-13 22:32:34 +0000 |
| commit | 4585cacaa9f9329a10aaf13a449151f5e9bc7a2c (patch) | |
| tree | f51b362b3308966dd7843fe153b7d35f98af57b3 /src/gui/kernel/qstylehints.cpp | |
| parent | 3d59a0f7c7321b611fd08a9fed94819c43e5dd79 (diff) | |
Add way to override when to show context menu
Add Qt::ContextMenuTrigger enum used with
QStyleHints::setContextMenuTrigger() to override default platform
behavior when to trigger context menu event.
The default is to show context menu on mouse press on
UNIX systems and on mouse release on Windows.
Give developer a possibility to override platform default behavior
to make cross platform application that behaves the same way on all
platforms
Task-number: QTBUG-93486
Change-Id: Ic832d3d8a7c355a8adb46868fff9cfd19988cf3c
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/gui/kernel/qstylehints.cpp')
| -rw-r--r-- | src/gui/kernel/qstylehints.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/gui/kernel/qstylehints.cpp b/src/gui/kernel/qstylehints.cpp index 0d15d114ec5..73c61997330 100644 --- a/src/gui/kernel/qstylehints.cpp +++ b/src/gui/kernel/qstylehints.cpp @@ -443,6 +443,40 @@ void QStyleHints::setShowShortcutsInContextMenus(bool s) } /*! + \property QStyleHints::contextMenuTrigger + \since 6.8 + \brief mouse event used to trigger a context menu event. + + The default on UNIX systems is to show context menu on mouse button press event, while on + Windows it is the mouse button release event. This property can be used to override the default + platform behavior. + + \note Developers must use this property with great care, as it changes the default interaction + mode that their users will expect on the platform that they are running on. + + \sa Qt::ContextMenuTrigger +*/ +Qt::ContextMenuTrigger QStyleHints::contextMenuTrigger() const +{ + Q_D(const QStyleHints); + if (d->m_contextMenuTrigger == -1) { + return themeableHint(QPlatformTheme::ContextMenuOnMouseRelease).toBool() + ? Qt::ContextMenuTrigger::Release + : Qt::ContextMenuTrigger::Press; + } + return Qt::ContextMenuTrigger(d->m_contextMenuTrigger); +} + +void QStyleHints::setContextMenuTrigger(Qt::ContextMenuTrigger contextMenuTrigger) +{ + Q_D(QStyleHints); + const Qt::ContextMenuTrigger currentTrigger = this->contextMenuTrigger(); + d->m_contextMenuTrigger = int(contextMenuTrigger); + if (currentTrigger != contextMenuTrigger) + emit contextMenuTriggerChanged(contextMenuTrigger); +} + +/*! \property QStyleHints::passwordMaskDelay \brief the time, in milliseconds, a typed letter is displayed unshrouded in a text input field in password mode. |
