0

Is it possible to use a property alias and gain access to KeyNaviagtion, assign an object to it, such that I can navigate between the buttons: cornerButton, messageButton and callButton? The cornerButton will be used to close the pop up. The code below does not run. I am trying to understand the concept.

cornerButton.KeyNavigation.down: messageButton
cornerButton.KeyNavigation.right: messageButton
Popup {
    id: root  
    property alias cornerButton: cornerButton
    
    Button {
         id: cornerButton
         visible: true
    }
}

Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

    Popup {
      //cornerButton.KeyNavigation.down: messageButton
      //cornerButton.KeyNavigation.right: messageButton
    

     Row {
        id: buttonsRow
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.bottom: parent.bottom

        UniButton {
            id: messageButton
            anchors.top: parent.top
            onClicked: {
                hide();
            }
            Keys.onReturnPressed: clicked()
            KeyNavigation.up: cornerButton
            KeyNavigation.down: callButton.enabled ? callButton : null
            KeyNavigation.left: cornerButton
            KeyNavigation.right: callButton.enabled ? callButton : null
            Keys.onPressed: {
                if (event.key === Qt.Key_F2 && callButton.enabled) {
                    callButton.focus = true
                }
            }
        }

        UniButton {
            id: callButton
            anchors.top: parent.top
            onClicked: {
                hide();
            }
            Keys.onReturnPressed: clicked()
            KeyNavigation.up: messageButton : null
            KeyNavigation.left: messageButton
            Keys.onPressed: {
                if (event.key === Qt.Key_F1) {
                    messageButton.focus = true
                }
            }
        }
    }
}

} }

test me
  • 47
  • 6
  • What is the error you're getting? – JarMan Mar 23 '22 at 20:43
  • `TypeError: Value is null and could not be converted to an object` and it would not display the pop anymore. If I remove `cornerButton.KeyNavigation.down: messageButton` `cornerButton.KeyNavigation.right: messageButton` it works as expected, however, the issue is when I navigate to the cornerButton, I am not able to navigate back down to the `messageButton` – test me Mar 23 '22 at 20:51

0 Answers0