在我的应用程序中,我有一个TextArea, 在它下面有一个带有Button项目的工具栏。每当Button按下 a 时,它TextArea就会失去焦点,并隐藏虚拟键盘(这是正确的)。但是,如果我想让TextAreaa 保持焦点,即使 aButton被按下了怎么办?
在 SailfishOS 中,Button它只是一个. MouseArea,而不是一个 QML Button。这意味着Button.activeFocusOnPress我没有可以设置为false. 有没有办法复制这种行为MouseArea?
这是一些代码:
TextArea {
id: editor
width: parent.width
height: 200
anchors.top: pageHeader.bottom
anchors.bottom: toolbar.top
}
ListModel {
id: textNavButtons
ListElement {buttonText: "left"}
ListElement {buttonText: "right"}
ListElement {buttonText: "tab"}
ListElement {buttonText: "home"}
ListElement {buttonText: "end"}
}
Row {
id: toolbar
anchors.bottom: parent.bottom
width: parent.width
height: 80
Repeater {
id: toolbarRepeater
model: textNavButtons
property int modelCount: model.count
delegate: Button {
text: buttonText
width: parent.width / toolbarRepeater.modelCount
onClicked: {
console.log("I was clicked: " + text);
}
}
}
}
编辑:我的目标是使用这些按钮在文本中插入标签,或使用 Home、End、Left、Right 等导航。我不确定使用这些按钮是否能实现目标,但我没有其他想法。我也必须模拟按键。