Frank Laritz
Frank Laritz

Reputation: 225

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
    }
}

Upvotes: 16

Views: 7253

Answers (2)

Moia
Moia

Reputation: 2354

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

TextField {
    anchors.centerIn: parent
    height: 50
    width: 100
    selectByMouse: true
}

Upvotes: 0

jpnurmi
jpnurmi

Reputation: 5836

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
    }
}

Upvotes: 20

Related Questions