在我的应用程序中,我有一个TextArea
,下面是一个包含Button
项的工具栏。每当按下Button
时,TextArea
就会失去焦点,并隐藏虚拟键盘(右侧)。但是,如果我希望TextArea
保持其焦点,即使按下了Button
,该怎么办?
在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等进行导航。我不确定使用这些按钮是否能实现目标,但我没有其他想法。我也必须模拟按键。
现在您可以使用
delegate: Button {
text: buttonText
width: parent.width / toolbarRepeater.modelCount
focusPolicy: Qt.NoFocus
onClicked: {
console.log("I was clicked: " + text);
}
}