Reputation: 1417
In my application, I have a TextArea
, and under it a toolbar with Button
items. Whenever a Button
gets pressed, the TextArea
loses focus, and hides the virtual keyboard (which is right). But what if I want the TextArea
to keep its focus, even if a Button
has been pressed?
In SailfishOS, Button
is just a MouseArea
, not a QML Button
. This means there is no property Button.activeFocusOnPress
that I could set to false
. Is there a way to replicate this behaviour for the MouseArea
?
Here's some code:
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);
}
}
}
}
EDIT: My goal is to use these buttons to insert tabs into the text, or to navigate with Home, End, Left, Right etc. I'm not sure if using these buttons will achieve the goal, but I had no other idea. I will have to simulate the keypress too.
Upvotes: 2
Views: 1697
Reputation: 1
Now you can use
delegate: Button {
text: buttonText
width: parent.width / toolbarRepeater.modelCount
focusPolicy: Qt.NoFocus
onClicked: {
console.log("I was clicked: " + text);
}
}
Upvotes: 0