2

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.

CamilB
  • 1,377
  • 1
  • 12
  • 27
  • For Button : `onFocusChanged : if(true == focus) { editor.focus = true }` – Amit Tomar Apr 13 '14 at 21:03
  • @AmitTomar why not an answer? And you can just do `if (focus) {` this is because `focus == true` will evaluate to a `bool`, which `focus` already is. – GabrielF Apr 15 '14 at 20:02
  • Unfortunately the solution suggested by @AmitTomar doesn't work very well. It does transfer the focus to the TextArea, but the virtual keyboard hides itself and stays hidden. – CamilB Apr 16 '14 at 15:39
  • @CamilB Probably you should try looking for ways to invoke the virtual keyboard manually using some sailfish API then. Is there a text element provided by them for similar purposes in their API? – Amit Tomar Apr 16 '14 at 17:08
  • @AmitTomar `Maliit` is the keyboard framework. It looks like it can be invoked, but I can't find any docs. also, there's the `com.jolla.keyboard` package in QML which is used by Maliit, but I'm yet to figure out how to use it, or even what it contains. – CamilB Apr 16 '14 at 17:19
  • 1
    @CamilB See if this could be of some help : https://gitorious.org/maliit/maliit-framework/source/f562ad91ee14680aaafc6401428ef259a9e61598:examples/apps/qml/enterKeyCustomization.qml I don't have the setup, so can't really test it. – Amit Tomar Apr 16 '14 at 19:27

1 Answers1

0

Now you can use

delegate: Button {
      text: buttonText
      width: parent.width / toolbarRepeater.modelCount
      focusPolicy: Qt.NoFocus
      onClicked: {
        console.log("I was clicked: " + text);
      }
    }