Details
-
Bug
-
Resolution: Fixed
-
P1: Critical
-
5.2.0
-
e426737d7 (dev), 56c39a262 (6.9), 3b598b6f7 (dev), dfcde3ea4 (6.9), 1ddae689c (dev), 7a59f5d90 (6.9), 89e98cd50 (6.9.0), 64063946d (dev), e5824ea91 (6.9)
Description
Native applications are expected to offer a context menu for input fields.
This is currently missing from QtQuick controls.
The example code below was my implementation for QtQuick 1.1. Though it should be easy to port this to QtQuick 2, I would have expected this to work out of the box.
import QtQuick 1.1 import QtDesktop 0.1 as Desktop MouseArea { id: editorContextMenu property Item editor signal menuShown anchors.fill: parent acceptedButtons: Qt.RightButton onPressed: { // selection gets lost due to focus loss var selectionStart = editor.selectionStart var selectionEnd = editor.selectionEnd var pos = mapToItem(null, mouseX, mouseY) menuLoader.sourceComponent = menuComponent menuLoader.item.showPopup(pos.x, pos.y) editor.select(selectionStart, selectionEnd) menuShown() } Component { id: menuComponent // Desktop.ContextMenu kann nicht direkt im Loader benutzt werden, da kein Item Item { function showPopup(x, y) { editmenu.showPopup(x, y) } Desktop.ContextMenu { id: editmenu onMenuClosed: menuLoader.sourceComponent = null Desktop.MenuItem { text: qsTr("cut") onTriggered: editor.cut() enabled: editor.selectedText.length > 0 } Desktop.MenuItem { text: qsTr("copy") onTriggered: editor.copy() enabled: editor.selectedText.length > 0 } Desktop.MenuItem { text: qsTr("paste") onTriggered: editor.paste() enabled: editor.canPaste } } } } Loader { id: menuLoader } }
Attachments
Issue Links
- depends on
-
QTBUG-133102 Adwaita theme icons not found on Ubuntu 24.04.1
-
- Reported
-
-
QTBUG-134604 edit-redo icon is clipped on Windows
-
- Reported
-
-
QTBUG-133302 ContextMenu opened on TextField sometimes closes immediately
-
- Closed
-
-
QTBUG-133424 Named platform icons are blurry on macOS when displayed with IconImage/IconLabel
-
- Closed
-
-
QTBUG-134798 Add support for ContextMenu on Android
-
- In Progress
-
-
QTBUG-132265 Defer creation of Menu until it's shown
-
- Closed
-
- is duplicated by
-
QTBUG-105531 Missing context menu for text fields
-
- Closed
-
- relates to
-
QTBUG-132422 Mouse cursor is I beam instead of arrow when opening ContextMenu in window-based popup over text editing control on Linux
-
- Open
-
-
QTBUG-99887 TapHandler on TextField (for showing right click context menu) stops working in Qt6
-
- Closed
-
-
QTBUG-133556 Allow disabling built-in ContextMenus of TextField and TextArea with a global flag
-
- In Progress
-
-
QTBUG-135007 Make CutAction etc. public so that it's easier for users to create their own text editing context menus
-
- Reported
-
-
QTBUG-67331 Make it possible to react to context menu events
-
- Closed
-
-
QTBUG-67621 Add contextMenuRequested() signal to Control
-
- Closed
-
- resulted in
-
QTBUG-134903 Duplicate context menus when using custom context Menus in text controls
-
- Open
-