[英]Mutually exclusive menu items in Qt Quick Controls 2
I want to specify mutually exclusive items in a submenu, using Qt Quick Controls 2. How to accomplish this? 我想在子菜单中指定互斥项目,使用Qt Quick Controls 2.如何实现这一目标? I suspect it somehow involves ActionGroup, but I don't see how a submenu can reference ActionGroup.
我怀疑它在某种程度上涉及ActionGroup,但我没有看到子菜单如何引用ActionGroup。 In the following main.qml I've defined an ActionGroup "shadeActions", and a sub Menu called "Shading".
在下面的main.qml中,我定义了一个ActionGroup“shadeActions”,以及一个名为“Shading”的子菜单。 How to incorporate the shadeActions ActionGroup into the Shading menu?
如何将shadeActions ActionGroup合并到Shading菜单中? Or is there another way to do it with Qt Controls 2?
或者Qt Controls 2有另一种方法吗?
main.qml: main.qml:
import QtQuick 2.9
import QtQuick.Controls 2.5
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("mbgrdviz")
ActionGroup {
id: shadeActions
exclusive: true
Action {checkable: true; text: qsTr("Off") }
Action {checkable: true; text: qsTr("Slope") }
Action {checkable: true; text: qsTr("Illumination") }
}
menuBar: MenuBar {
Menu {
title: qsTr("&File")
Action { text: qsTr("&Open overlay grid...") }
Action { text: qsTr("&Open site...") }
Action { text: qsTr("&Open route...") }
Action { text: qsTr("&Open navigation...") }
MenuSeparator { }
Action { text: qsTr("&Exit") }
}
Menu {
title: qsTr("&View")
Action { checkable: true; text: qsTr("&Map") }
Action { checkable: true; text: qsTr("&Topography") }
Action { checkable: true; text: qsTr("&Slope") }
Action { checkable: true; text: qsTr("&Histograms") }
Action { checkable: true; text: qsTr("&Contours") }
Action { checkable: true; text: qsTr("&Sites") }
Action { checkable: true; text: qsTr("&Routes") }
Action { checkable: true; text: qsTr("&Vector") }
Action { checkable: true; text: qsTr("&Profile window") }
MenuSeparator {}
Menu {
title: "Shading" // menu items should be exclusively selectable
Action {checkable: true; text: qsTr("Off") }
Action {checkable: true; text: qsTr("Slope")}
Action {checkable: true; text: qsTr("Illumination") }
}
}
Menu {
title: qsTr("&Help")
Action { text: qsTr("&About") }
}
}
SwipeView {
id: swipeView
anchors.fill: parent
currentIndex: tabBar.currentIndex
Page1Form {
}
Page2Form {
}
}
footer: TabBar {
id: tabBar
currentIndex: swipeView.currentIndex
TabButton {
text: qsTr("Page 1")
}
TabButton {
text: qsTr("Page 2")
}
}
}
By doing this: 通过做这个:
ActionGroup {
id: shadeActions
exclusive: true
Action {checkable: true; text: qsTr("Off") }
Action {checkable: true; text: qsTr("Slope") }
Action {checkable: true; text: qsTr("Illumination") }
}
You are duplicating you actions and the ones in you menu are not grouped. 您正在复制您的操作,并且菜单中的操作未分组。 So, create your group without actions:
因此,无需操作即可创建您的组:
ActionGroup {
id: shadeActions
}
Then, assign your actions to the group: 然后,将您的操作分配给该组:
Menu {
title: "Shading" // menu items should be exclusively selectable
Action {checkable: true; text: qsTr("Off"); ActionGroup.group: shadeActions }
Action {checkable: true; text: qsTr("Slope"); ActionGroup.group: shadeActions }
Action {checkable: true; text: qsTr("Illumination"); ActionGroup.group: shadeActions }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.