Details
-
Suggestion
-
Resolution: Unresolved
-
P2: Important
-
5.2.0
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
- relates to
-
QTBUG-99887 TapHandler on TextField (for showing right click context menu) stops working in Qt6
- Closed
-
QTBUG-67331 Make it possible to react to context menu events
- Open
-
QTBUG-67621 Add contextMenuRequested() signal to Control
- Closed