Взаимоисключающие пункты меню в Qt Quick Controls 2 - PullRequest
0 голосов
/ 25 апреля 2019

Я хочу указать взаимоисключающие элементы в подменю, используя Qt Quick Controls 2. Как это сделать? Я подозреваю, что это как-то связано с ActionGroup, но я не понимаю, как подменю может ссылаться на ActionGroup. В следующем main.qml я определил ActionGroup «shadeActions» и подменю «Shading». Как включить ActionGroup ShadeActions в меню 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")
        }
    }
}

image Shading">

1 Ответ

0 голосов
/ 25 апреля 2019

Делая это:

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

...