Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 909
DenisB Avatar asked Oct 24 '25 05:10

DenisB


1 Answers

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}
like image 132
DenisB Avatar answered Oct 26 '25 19:10

DenisB



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!