Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Not to close Menu on MenuItem Click
QtWS25 Last Chance

Not to close Menu on MenuItem Click

Scheduled Pinned Locked Moved Unsolved General and Desktop
menubuttonmenuitem
5 Posts 3 Posters 2.8k Views
  • 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.
  • A Offline
    A Offline
    ars1614
    wrote on 23 Aug 2016, 13:09 last edited by
    #1

    Hi! I have a button with a menu like this:

    Button {
    	tooltip: qsTr("Filters")
    	style: ButtonStyle {
    		background: Rectangle {
    			implicitWidth: TextSingleton.pixelDeviceRatio * 24
    			implicitHeight: TextSingleton.pixelDeviceRatio * 24
    			x: control.pressed ? -1 : 0
    			y: control.pressed ? 1 : 0
    			color: "transparent"
    			Image {
    				anchors.fill: parent
    				source: control.hovered ? "qrc:///img/res/img/filters_w_hover.png" 
                                            : "qrc:///img/res/img/filters_w.png"
    				mipmap: true
    			}
    		}
    	}
    
    	menu: Menu {
    		id: filtersMenu
    		
    		MenuItem {
    			id: menuItemTitle
    			text: qsTr("Title")
    			checkable: true
    			checked: false  
    		}
    
    		MenuItem {
    			id: menuItemDescription
    			text: qsTr("Description")
    			checkable: true
    			checked: false
    		}
    	}
    }
    

    I would like the menu does not close when the items are clicked, to be able to select some filters without having to open the menu again.

    1 Reply Last reply
    1
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 23 Aug 2016, 14:48 last edited by
      #2

      Hi
      All normal main menus ever known to man, has always closed when you choose an item.
      So are u sure a menu is the right way of selecting filters ?
      :)

      A 1 Reply Last reply 23 Aug 2016, 15:30
      0
      • M mrjj
        23 Aug 2016, 14:48

        Hi
        All normal main menus ever known to man, has always closed when you choose an item.
        So are u sure a menu is the right way of selecting filters ?
        :)

        A Offline
        A Offline
        ars1614
        wrote on 23 Aug 2016, 15:30 last edited by
        #3

        @mrjj For example, in many programs, when you are choosing toolbars, the rightmenu does not close what allows to choose some of them at once. I was thinking in implement the same.
        From your answer... I suppose there's no way to do it with Menu component, doesn't it?

        M 1 Reply Last reply 23 Aug 2016, 19:58
        1
        • A ars1614
          23 Aug 2016, 15:30

          @mrjj For example, in many programs, when you are choosing toolbars, the rightmenu does not close what allows to choose some of them at once. I was thinking in implement the same.
          From your answer... I suppose there's no way to do it with Menu component, doesn't it?

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 23 Aug 2016, 19:58 last edited by
          #4

          @ars1614
          ok. never seen it then :)
          I would not rule out you can override it closing on menu selection by subclassing
          or using event filter.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            asc7uni
            wrote on 9 Mar 2021, 07:31 last edited by asc7uni 3 Sept 2021, 07:31
            #5

            Just changing MenuItem to CheckBox does the job. Menu stays as long as you clicking CheckBox items:

             Menu {
                    CheckBox {
                        text: "Item A"
                        checkable: true
                        checked: false
                        onCheckedChanged: {
                            console.debug("item A", checked)
                        }
                    }
                    CheckBox {
                        text: "Item B"
                        checkable: true
                        checked: false
                        onCheckedChanged: {
                            console.debug("item B", checked)
                        }
                    }
                }
            

            This topic is still high in search results, so I think it would be helpful to post correct answer. Despite question is old it is still useful.

            1 Reply Last reply
            1

            • Login

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