Details
-
Bug
-
Resolution: Duplicate
-
P2: Important
-
None
-
5.12.1
-
None
Description
Whilst trying to implement a right click copy/paste context menu for TextArea/TextField (QTBUG-35598) I've been faced with the problem that the selection of TextInput/TextEdit is cleared on opening the menu or hovering an item. This obviously prevents the use of the copy/cut methods.
The reason for this is that Popup and Menu do not use the correct focus reason when stealing the focus from the input fields.
I'll post a patch for discussion of a solution on gerrit.
import QtQuick 2.12 import QtQuick.Window 2.12 import QtQuick.Controls 2.12 Window { visible: true width: 640 height: 480 title: qsTr("Hello World") TextField { id: tf anchors.centerIn: parent width: 400 text: "Bla Bla" selectByMouse: true TapHandler { acceptedButtons: Qt.RightButton onTapped: menu.popup(tf) } Menu { id: menu MenuItem { focusPolicy: Qt.NoFocus text: "Copy" enabled: tf.selectedText !== "" onTriggered: tf.copy() } MenuItem { focusPolicy: Qt.NoFocus text: "Cut" enabled: tf.selectedText !== "" && !tf.readOnly onTriggered: tf.cut() } MenuItem { focusPolicy: Qt.NoFocus text: "Paste" onTriggered: tf.paste() } } } }
Attachments
Issue Links
- duplicates
-
QTBUG-71723 When showing a context menu for a TextField then it will lose the selection instead of keeping it
- Closed