【问题标题】:Long strings in Qml TextFieldQml TextField中的长字符串
【发布时间】:2018-02-05 14:18:03
【问题描述】:

在我的项目中,我使用 QML TextField。我想在使用长字符串时正确表示光标。主要问题出现了,当我们将光标设置在字符串的中间并开始输入文本时。在这种情况下,文本出现在光标的左侧,但它不会移动光标!我想在输入文本时创建光标移动到右侧,直到它到达右侧。

TextField {
    font.pixelSize: parent.height * 0.7

    anchors.fill: parent
    anchors.verticalCenter: parent.verticalCenter

    text: parent.text

    cursorPosition: parent.cursorPosition
    cursorVisible: true
}

【问题讨论】:

  • 已经尝试您的代码消除了text: parent.textcursorPosition: parent.cursorPosition 并且它工作正常,您可以提供一个minimal reproducible example,例如,当我运行您的代码时,我收到一个错误,因为没有定义父级,也不是你指出父母是什么类型。

标签: qt qml textfield


【解决方案1】:

问题出在文本编辑方法上。我使用了 Q_PROPERTY() 。更改文本时,TextField 中的文本将完全删除,然后粘贴新文本。它将光标移动到行尾,然后在 Q_PROPERTY() 中设置光标会导致上述问题。

解决方案是使用 TextField 方法,例如 remove() 和 insert()。

【讨论】:

    猜你喜欢
    • 2016-03-24
    • 2016-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多