Dynamically created Menu is triggered by space key



  • Hi,

    When I have a menu which is created on demand, after first request - it can be triggered by space key press what is completely undesired.
    Here is example code:

    import QtQuick 2.9
    import QtQuick.Controls 2.2
    import QtQuick.Window 2.2
    
    
    ApplicationWindow {
      visible: true
    
      property Menu menu: null
    
      Button {
        text: "get menu"
        onClicked: {
          if (!menu)
            menu = menuComp.createObject(this)
          menu.open()
        }
      }
    
      Component {
        id: menuComp
        Menu {
          width: 200; height: 400
          MenuItem {
            text: "action 1"
          }
          MenuItem {
            text: "action 2"
          }
        }
      }
    }
    

    Do You think it is a bug or a kind of my misusing?



  • I think it's because the menu gets the keyboard focus when it's created.



  • Have You any idea how to get rid of this?
    I just checked activeFocus of menu is always false whether menu is visible or not and focus is false by default



  • The following seems to work:

        onClicked: {
          if (!menu)
            menu = menuComp.createObject(this)
          menu.open()
          menu.focus = false
        }
    


  • @Wieland
    Works, but only first time...
    When menu is ignored by pressing ESC or clicking outside, problem comes back, but when menu item is selected menu doesn't react on space key.



  • Mhh, maybe this?

        onClicked: {
          if (!menu)
            menu = menuComp.createObject(this)
          menu.open()
          focus = false // remove focus from the button on click
         }
    


  • Brilliant!

    Thank You!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.