Question

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.

Était-ce utile?

La solution

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}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top