【发布时间】:2014-04-13 05:48:24
【问题描述】:
我在屏幕上有两个元素,一个 Rectangle 和一个 TextInput。当在矩形上设置了 activefocus 并且我键入任何内容时,我需要将键入的输入输入到 TextInput
为此,我使用了curRect.Keys.forwardTo = [curTextbox];
它工作正常,但我也想在焦点位于矩形时看到光标。
http://qt-project.org/doc/qt-4.8/qml-textinput.html#cursorVisible-prop
在上面的QT链接中,它说
that 可以直接在脚本中设置,例如如果一个 KeyProxy 可能会将密钥转发给它,并且您希望它在这个时候看起来很活跃 发生(但实际上并没有给予它积极的关注)。
但在我的情况下不会发生这种情况。
谁能向我解释为什么会这样以及如何实现我的目标,即即使 activeFocus 在矩形上也能显示光标?
即使在输入文本时显示光标也很棒。
更新:
import QtQuick 1.0
FocusScope{
width: 400
height: 400
TextInput {Rectangle{anchors.fill: parent;color:"#66ff0000"}
id: mytext
anchors.top:parent.top
cursorVisible: true
width: rect.width
MouseArea{
anchors.fill: parent;
onClicked: mytext.forceActiveFocus()
}
Keys.onDownPressed: {
mytext2.forceActiveFocus();
}
}
TextInput {Rectangle{anchors.fill: parent;color:"#66ff0000"}
id: mytext2
anchors.top:mytext.bottom
cursorVisible: true
width: rect.width
MouseArea{
anchors.fill: parent;
onClicked: mytext2.forceActiveFocus()
}
Keys.onUpPressed: {
mytext.forceActiveFocus();
}
}
Rectangle {
id:rect
width: 360
height: 360
color:rect.activeFocus?"#6600ff00":"#660000ff"
focus: true
Keys.forwardTo: mytext
MouseArea{
anchors.fill: parent;
onClicked: rect.forceActiveFocus()
}
}
Component.onCompleted: rect.forceActiveFocus();
}
提前致谢。
【问题讨论】:
-
抱歉,这是不可能的。您可以随时输入 |在模糊上签名,这样输入中就会有一些东西。但它不会眨眼。在焦点上,您可以将光标移回管道所在的位置并将其删除。
-
@JakubPolomský 你确定吗?文档似乎表明它是。不过,我从未尝试过。
-
我认为将活动焦点转移到 TextInput 可能更容易,为什么你没有选择?
-
你是怎么做到的?我可以让它以最直接的方式工作。有关代码,请参阅我的答案。提供代码以便我们更好地帮助您。
-
您好,请查看我添加的示例代码
标签: javascript qt qml