Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt Quick Controls 2.0 Text Field Cannot Select Text

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
    }
}
like image 710
Frank Laritz Avatar asked Aug 08 '16 15:08

Frank Laritz


1 Answers

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
    }
}
like image 148
jpnurmi Avatar answered Oct 27 '22 10:10

jpnurmi