从属性别名访问 KeyNaviagtion
是否可以使用属性别名并访问 KeyNaviagtion,为其分配一个对象,以便我可以在按钮之间导航: cornerButton
、messageButton
和 呼叫按钮?
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论