15

I'm having difficulty with selecting text on a TextField from Qt Quick Controls 2.0 with a mouse. When I hover over the TextField the cursor does not change from the cursor arrow to the cursor I beam and I am unable to select text. I verified text selection is possible by using the keyboard shortcut Ctrl+A. I also tested this with the TextField from Qt Quick Controls 1.4, and it works as expected (the mouse cursor changes to an I beam and I can select text). I think I must be missing something obvious because this seems like basic text field functionality. Does anyone have any ideas? Below is my code:

import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0

ApplicationWindow {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

    TextField {
        anchors.centerIn: parent
        height: 50
        width: 100
    }
}
Frank Laritz
  • 215
  • 3
  • 7

2 Answers2

20

You can use selectByMouse: true to enable mouse selection. This is typically not desired on embedded and mobile platforms. As for the mouse cursor, it will be fixed in Qt 5.7.1. As a temporary workaround, you can use a MouseArea.

TextField {
    selectByMouse: true
    MouseArea {
        anchors.fill: parent
        cursorShape: Qt.IBeamCursor
        acceptedButtons: Qt.NoButton
    }
}
Georg Schölly
  • 124,188
  • 49
  • 220
  • 267
jpnurmi
  • 5,716
  • 2
  • 21
  • 37
  • Thank you. I'm developing a desktop app, so being able to select by mouse is definitely desired. I tested your temporary workaround and found it to be satisfactory. Thanks for the help! – Frank Laritz Aug 11 '16 at 17:17
0

TextField has now the property selectByMouse, so it's enough to enable it.

TextField {
    anchors.centerIn: parent
    height: 50
    width: 100
    selectByMouse: true
}
Moia
  • 2,216
  • 1
  • 12
  • 34