[Solved] How to detect Menu closed or dismissal?



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



  • 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?



  • 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



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


Log in to reply
 

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