Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-73807

TextEdit selection is cleared when opening a Copy/Paste context menu

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P2: Important
    • None
    • 5.12.1
    • Quick: Controls 2
    • 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

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              qt.team.quick.subscriptions Qt Quick and Widgets Team
              njeisecke Nils Jeisecke
              Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There is 1 open Gerrit change