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. Exclusive menu item check-mark not working
Forum Updated to NodeBB v4.3 + New Features

Exclusive menu item check-mark not working

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 283 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.
  • Tom assoT Offline
    Tom assoT Offline
    Tom asso
    wrote on last edited by Tom asso
    #1

    I am running Qt 6.8 on ubuntu 22.04.3.
    My QML dynamically adds checkable MenuItems to a menu, using Repeater and a model. I want those items to be exclusively checkable, but they are not; i.e. when I select an item, it becomes checked - as are all previously selected item:

    	Menu {
    	    title: 'Mouse mode'
    	    id: mouseModesMenu
                Repeater {
    	      model: mouseModes
    	      visible: true
    	      MenuItem {
    	        text: modelData; checkable: true;
                    ActionGroup.group: mouseModeActions
                    onTriggered: { console.log('selected ', modelData);
    		               topoDataItem.setMouseMode(modelData)}		
    	      }
    	    }
    	  }
    
        ActionGroup {
            id: mouseModeActions
            exclusive: true
        }
    
    

    What am I doing wrong?
    Thanks!

    1 Reply Last reply
    0
    • Christian EhrlicherC Christian Ehrlicher moved this topic from General and Desktop on
    • S Offline
      S Offline
      SuhasKrishanamurthy
      wrote on last edited by
      #2

      Use Actions inside the Repeater, associate them with the ActionGroup, and bind them to the MenuItem.

      Menu {
          title: "Mouse mode"
          id: mouseModesMenu
      
          Repeater {
              model: mouseModes
      
              Action {
                  id: mouseAction
                  text: modelData
                  checkable: true
                  ActionGroup.group: mouseModeActions
      
                  onTriggered: {
                      console.log("selected", modelData)
                      topoDataItem.setMouseMode(modelData)
                  }
              }
      
              delegate: MenuItem {
                  action: mouseAction
              }
          }
      }
      
      ActionGroup {
          id: mouseModeActions
          exclusive: true
      }
      
      
      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