Search code examples
qtqmlqtquick2qt-quick

DropDown menu with QtQuickControls2 on Qt application


on qt quick controls 2, how can I configure a button Item with a dropdown menu of others buttons. When the user click on this button is triggered onClicked signal and under the button should be open a dropdown menu with other buttons. I have try with ButtonGroup but I don't know if this is the best practice. There is some Controls2 item to be use? Thanks in advice

Best Regards Daniele


Solution

  • There is Menu from QtQuick.Controls 2.0 that can do what you want.

    Example taken from the documentation :

    Popup button menu

    Button {
        id: fileButton
        text: "File"
        onClicked: menu.open()
    
        Menu {
            id: menu
            y: fileButton.height
    
            MenuItem {
                text: "New..."
            }
            MenuItem {
                text: "Open..."
            }
            MenuItem {
                text: "Save"
            }
        }
    }