Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-66113

Nested popups cause Keys.onBackPressed event handler to not be executed

    XMLWordPrintable

Details

    • f301decbe39d253cc979774e2f32cde9c1212e4c

    Description

      I have a use case where a popup for entering notes can spawn a sub-popup for grabbing an image via the QML Camera component.

      The nested popups seem to cause Qt/ QML to lose track of my StackView's `Keys.onBackPressed` event listener such that when I go into the nested popup and then come out of both popups, the default Android behavior of exiting the app is performed.

      The below S.S.C.C.E. manifests this behavior:

      import QtQuick 2.9
      import QtQuick.Controls 2.2
      import QtQuick.Dialogs 1.2
      
      ApplicationWindow {
        id: root;
        visible: true
        width:400;
        height:200;
        
        StackView {
          id: stack_view;
          Component.onCompleted: {
            push(_HomeComponent)
          }
          Keys.onBackPressed: {
            console.log('BackPressed intercepted and stopped from quitting the program.');
          }
        }
        
        Component {
          id: _HomeComponent;
          Item {
            Button {
              text: 'open popup';
              onClicked: { 
                popup.visible = true;
                console.log('open popup clicked');
              }
            }
            Popup {
              id: popup
              visible: false;
              parent: ApplicationWindow.contentItem;
              Component {
                id: _PopupContent;
                Rectangle {
                  color: 'grey';
                  width: 150;
                  height: 150;
                  Button {
                    text: 'open nested popup';
                    onClicked: { 
                      nested_popup.visible = true;
                      console.log('open nested popup clicked');
                    }
                  }
                  Popup {
                    id: nested_popup
                    visible: false;
                    parent: ApplicationWindow.contentItem;
                    Component {
                      id: _NestedPopupContent;
                      Rectangle {
                        color: 'red';
                        width: 150;
                        height: 150;
                        Text {text: 'In nested popup'}
                      }
                    }
                    
                    Loader {
                      sourceComponent: nested_popup.visible ? _NestedPopupContent : null;
                    }
                  }
                }
              }
              Loader {
                sourceComponent: popup.visible ? _PopupContent : null;
              }
            }
          }
        }
      }
      
      

      Attached is a gif of the code in action. Blocking if only one popup is gone into and exiting if the nested popup is gone into.

      Attachments

        Activity

          People

            Unassigned Unassigned
            ross.rogers Ross Rogers
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: