Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Placing a Button at the right edge of Menubar



  • Hi,

    I have a QML application which uses ApplicationWindow with a QuickControls2 MenuBar which spans the width of the window. I would like to add a button at the right end side of this menu. This button should control the expansion of a right-hand toolbar. How can this be done?



  • You can set parent for a button like this:

    ApplicationWindow {
        id: window
        width: 320
        height: 260
        visible: true
    
        menuBar: MenuBar {
            Menu {
                title: qsTr("&File")
                Action { text: qsTr("&New...") }
                Action { text: qsTr("&Open...") }
                Action { text: qsTr("&Save") }
                Action { text: qsTr("Save &As...") }
                MenuSeparator { }
                Action { text: qsTr("&Quit") }
            }
            Menu {
                title: qsTr("&Edit")
                Action { text: qsTr("Cu&t") }
                Action { text: qsTr("&Copy") }
                Action { text: qsTr("&Paste") }
            }
            Menu {
                title: qsTr("&Help")
                Action { text: qsTr("&About") }
            }
    
        }
        ToolButton {
            anchors.right: parent.right
            parent: window.menuBar // Set main menu toolbar as parent for tool button
            text: "⋮"
        }
    }
    

Log in to reply