14

我在使用鼠标从 Qt Quick Controls 2.0 中选择TextField上的文本时遇到了困难。当我将鼠标悬停在 TextField 上时,光标不会从光标箭头变为我发出的光标,并且我无法选择文本。我验证了可以使用键盘快捷键 Ctrl+A 进行文本选择。我还使用 Qt Quick Controls 1.4 中的TextField对此进行了测试,它按预期工作(鼠标光标变为 I 光束,我可以选择文本)。我想我一定遗漏了一些明显的东西,因为这似乎是基本的文本字段功能。有没有人有任何想法?下面是我的代码:

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

2 回答 2

19

您可以使用selectByMouse: true来启用鼠标选择。这在嵌入式和移动平台上通常是不需要的。至于鼠标光标,它将在 Qt 5.7.1 中修复。作为临时解决方法,您可以使用MouseArea.

TextField {
    selectByMouse: true
    MouseArea {
        anchors.fill: parent
        cursorShape: Qt.IBeamCursor
        acceptedButtons: Qt.NoButton
    }
}
于 2016-08-10T19:53:58.517 回答
0

TextField现在有了属性selectByMouse,所以启用它就足够了。

TextField {
    anchors.centerIn: parent
    height: 50
    width: 100
    selectByMouse: true
}
于 2021-03-17T11:23:11.973 回答