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. [Solved] How to detect Menu closed or dismissal?
Qt 6.11 is out! See what's new in the release blog

[Solved] How to detect Menu closed or dismissal?

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 1 Posters 2.1k Views 1 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.
  • Q Offline
    Q Offline
    qt_sur
    wrote on last edited by
    #1

    Hi,

    I need to show certain visual changes on the UI only during the time when the Menu object is opened and user is about to select something. But the issue occurs when the user just dismisses the Menu and doesn't select anything - I can't seem to get any signals back. Here is the code from a simple test app:

    @import QtQuick 2.0
    import QtQuick.Controls 1.0 // needed for Label, Button

    Rectangle {
    width: 600
    height: 600

    Rectangle {
        id: clickableRect
        focus: true
    
        color: "red"
        width: 300
        height: 300
        anchors.centerIn: parent
    
        ExclusiveGroup {
            id: myGroup
        }
    
        Menu {
            id: myMenu
    
            onVisibleChanged: {
                console.log("myMenu : onVisibleChanged");
            }
            onEnabledChanged: {
                console.log("myMenu : onEnabledChanged");
            }
    

    // on__menuClosed: { // <---- This appears to be a private signal but Qt Creator still allows me to auto complete this signal handler. However, runtime doesn't allow execution.
    // It says "Cannot assign to non-existent property "on__menuClosed"
    // console.log("myMenu : on__menuClosed");
    // }

            MenuItem {
                text: "Menu Item 1"
                checkable: true
                exclusiveGroup: myGroup
            }
            MenuItem {
                text: "Menu Item 2"
                checkable: true
                exclusiveGroup: myGroup
            }
        } // Menu
    
        onFocusChanged: {
            console.log("clickableRect : onFocusChanged");
        }
        onActiveFocusChanged: {
            console.log("clickableRect : onActiveFocusChanged");
        }
    }
    
    
    MouseArea {
        anchors.fill: parent
        onClicked: {
            //myFocusScope.focus = false;
            clickableRect.focus = false;
            myMenu.popup();
        }
        onFocusChanged: {
            console.log("MouseArea : onFocusChanged");
        }
        onActiveFocusChanged: {
            console.log("MouseArea : onActiveFocusChanged");
        }
    }
    
    
    onFocusChanged: {
        console.log("root Rectangle : onFocusChanged");
    }
    onActiveFocusChanged: {
        console.log("root Rectangle : onActiveFocusChanged");
    }
    

    }
    @

    I also tried some stuff with FocusScope but couldn't make it to work. Any help will be appreciated.

    Thanks.

    1 Reply Last reply
    0
    • Q Offline
      Q Offline
      qt_sur
      wrote on last edited by
      #2

      No responses so far; is it safe to assume that no such mechanism exist to detect the closing or dismissal of the Menu object? Does that mean I need to implement my own context Menu?

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        qt_sur
        wrote on last edited by
        #3

        Haven't found any resolution yet. I am assuming that this might just be a bug with the new Qt 5.3 (at least on Windows); another person on the #qt-quick IRC channel had the same assumption.

        So logged a bug: https://bugreports.qt-project.org/browse/QTBUG-39740#comment-247757

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          qt_sur
          wrote on last edited by
          #4

          As per the bug report comment, there seems to be a work around (for now, at least). So closing of this forum post as "Solved".
          "
          on__PopupVisibleChanged: console.log("visible " + __popupVisible)
          The implementation can change without warning in future versions of Qt, but you could use it as a workaround for now.
          "

          The issue is being picked up as a feature request, for Qt 5.4.

          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