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. Dynamically created Menu is triggered by space key
Qt 6.11 is out! See what's new in the release blog

Dynamically created Menu is triggered by space key

Scheduled Pinned Locked Moved Solved QML and Qt Quick
7 Posts 2 Posters 2.0k 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.
  • SeeLookS Offline
    SeeLookS Offline
    SeeLook
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • SeeLookS Offline
        SeeLookS Offline
        SeeLook
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          The following seems to work:

              onClicked: {
                if (!menu)
                  menu = menuComp.createObject(this)
                menu.open()
                menu.focus = false
              }
          
          SeeLookS 1 Reply Last reply
          1
          • ? A Former User

            The following seems to work:

                onClicked: {
                  if (!menu)
                    menu = menuComp.createObject(this)
                  menu.open()
                  menu.focus = false
                }
            
            SeeLookS Offline
            SeeLookS Offline
            SeeLook
            wrote on last edited by
            #5

            @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.

            1 Reply Last reply
            0
            • ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #6

              Mhh, maybe this?

                  onClicked: {
                    if (!menu)
                      menu = menuComp.createObject(this)
                    menu.open()
                    focus = false // remove focus from the button on click
                   }
              
              1 Reply Last reply
              2
              • SeeLookS Offline
                SeeLookS Offline
                SeeLook
                wrote on last edited by
                #7

                Brilliant!

                Thank You!

                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