Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Menu without Menuitem

Menu without Menuitem

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 1.1k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    PhTe
    wrote on last edited by
    #1

    I have a menubar with some menus on it. My problem is that some of the menus should have no items. So just by clicking on the menu name an action should be performed or a function called or something like this.

    MenuBar {
            Menu {
                title: qsTr("File")
    
                MenuItem { text: qsTr("Open") }
                MenuItem { text: qsTr("Save") }
                MenuSeparator { }
                MenuItem { text: qsTr("Close") }
            }
            
            Menu {
                title: qsTr("Tools");
            }
    }
    

    Like in the sample above, if the user clicks on the Menu 'Tools' there should be an action. As far as i can see there is no 'onclick' or 'onTriggered' handler for the Menu, just for MenuItem.

    Does anyone have an idea?

    1 Reply Last reply
    1
    • P Offline
      P Offline
      PhTe
      wrote on last edited by
      #2

      Has no one an idea how to add a single clickable item to a menubar?

      T 1 Reply Last reply
      0
      • P PhTe

        Has no one an idea how to add a single clickable item to a menubar?

        T Offline
        T Offline
        tarod.net
        wrote on last edited by tarod.net
        #3

        @PhTe You could use the signal handleronAboutToShow or even onPopupVisibleChanged

        Example:

        import QtQuick 2.5
        import QtQuick.Window 2.2
        import QtQuick.Controls 1.4
        
        ApplicationWindow {
            visible: true
        
            menuBar:MenuBar {
                Menu {
                    title: qsTr("File")
        
                    MenuItem { text: qsTr("Open") }
                    MenuItem { text: qsTr("Save") }
                    MenuSeparator { }
                    MenuItem { text: qsTr("Close") }
                }
        
                Menu {
                    id: emptyMenu
                    title: qsTr("Tools");
        
                    onPopupVisibleChanged: console.log("emptyMenu - onPopupVisibleChanged")
        
                    onAboutToShow: {
                        console.log("emptyMenu - onAboutToShow")
                    }
                }
            }
        
            Menu { 
                id: contextMenu
                MenuItem {
                    text: qsTr('Delete')
                }
        
                onAboutToShow: {
                    console.log("contextMenu - onAboutToShow")
                }
            }
        
            MainForm {
                anchors.fill: parent
                mouseArea.onClicked: {
                    contextMenu.popup()
                }
            }
        }
        

        "Individually, we are one drop. Together, we are an ocean."

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved