从属性别名访问 KeyNaviagtion

发布于 2025-01-16 15:00:49 字数 1975 浏览 2 评论 0原文

是否可以使用属性别名并访问 KeyNaviagtion,为其分配一个对象,以便我可以在按钮之间导航: cornerButtonmessageButton呼叫按钮? cornerButton 将用于关闭弹出窗口。下面的代码无法运行。我正在尝试理解这个概念。

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
                }
            }
        }
    }
}

} }

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
                }
            }
        }
    }
}

}
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文