[英]Mutually exclusive menu items in Qt Quick Controls 2
我想在子菜單中指定互斥項目,使用Qt Quick Controls 2.如何實現這一目標? 我懷疑它在某種程度上涉及ActionGroup,但我沒有看到子菜單如何引用ActionGroup。 在下面的main.qml中,我定義了一個ActionGroup“shadeActions”,以及一個名為“Shading”的子菜單。 如何將shadeActions ActionGroup合並到Shading菜單中? 或者Qt Controls 2有另一種方法嗎?
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")
}
}
}
通過做這個:
ActionGroup {
id: shadeActions
exclusive: true
Action {checkable: true; text: qsTr("Off") }
Action {checkable: true; text: qsTr("Slope") }
Action {checkable: true; text: qsTr("Illumination") }
}
您正在復制您的操作,並且菜單中的操作未分組。 因此,無需操作即可創建您的組:
ActionGroup {
id: shadeActions
}
然后,將您的操作分配給該組:
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.