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
- depends on
-
QTBUG-133302 ContextMenu opened on TextField sometimes closes immediately
- Reported
-
QTBUG-133424 Native theme icons are blurry on macOS when displayed with IconImage/IconLabel
- Reported
-
QTBUG-132265 Defer creation of Menu until it's shown
- Closed
- relates to
-
QTBUG-132422 Mouse cursor is I beam instead of arrow when opening menu in window-based popup over text editing control
- Reported
-
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
- Closed
-
QTBUG-67621 Add contextMenuRequested() signal to Control
- Closed
Gerrit Reviews
For Gerrit Dashboard: QTBUG-35598 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
612253,56 | ContextMenu: add to text editing controls | dev | qt/qtdeclarative | Status: NEW | 0 | 0 |
618449,6 | iOS: send context menu event rather than instantly showing edit menu | dev | qt/qtbase | Status: NEW | +2 | 0 |