DenisB
DenisB

Reputation: 165

QML : Link MenuBar and ToolBar actions

I'm quite new to Qt Quick (and Qt in general), and i'd like to have an advice on "good way" to do this.

In an application, if I have a menubar and toolbar that have common actions, is there a way to link the buttons from menubar and buttons from toolbar ?

For instance, if I have a "save" function. This action is avaible through menubar and toolbar. How can I mutualise this action ?

At the moment, the best way i've found is to create a function "save" that is called by both buttons.

Upvotes: 2

Views: 1713

Answers (1)

DenisB
DenisB

Reputation: 165

I've actually found a "good practice" for this problem on QML example : use Action items.

For instance :

FileDialog {
    id: openDialog
    onAccepted: myData.source= fileUrl
}

Action {
    id: openFile
    iconSource: "images/fileopen.png"
    text: "Open"
    onTriggered: openDialog.open()
}

menuBar: MenuBar {
    Menu {
       MenuItem { action : openFile }

// ....

toolBar : ToolBar {
        ToolButton { action:openFile}

Upvotes: 4

Related Questions