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

Popups should restore focus to the contentItem of ApplicationWindow upon closing

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 5.7.0 RC
    • 5.7
    • Quick: Controls 2
    • None
    • eb6e122c68333382309843ad96e7d04d2c5a3595

    Description

      Run the application below:

      import QtQuick 2.6
      import QtQuick.Layouts 1.1
      import QtQuick.Window 2.2
      import QtQuick.Controls 2.0
      
      ApplicationWindow {
          width: 400
          height: 200
          visible: true
      
          onActiveFocusItemChanged: print("activeFocusItem", activeFocusItem)
      
          header: ToolBar {
              RowLayout {
                  ToolButton {
                      text: qsTr("File")
                      onClicked: fileMenu.open()
      
                      Menu {
                          id: fileMenu
                          y: parent.height
      
                          MenuItem {
                              text: qsTr("New")
                          }
                          MenuItem {
                              text: qsTr("open")
                          }
                          MenuItem {
                              text: qsTr("Close")
                          }
                      }
                  }
              }
          }
      
          FocusScope {
              id: focusScope
              focus: true
              anchors.fill: parent
      
              property bool toggled: false
              onToggledChanged: print("toggled", toggled)
      
              Keys.onPressed: {
                  if (event.modifiers === Qt.AltModifier) {
                      focusScope.toggled = true;
                  }
              }
              Keys.onReleased: {
                  if ((event.modifiers === Qt.AltModifier || event.key === Qt.Key_Alt) && !event.isAutoRepeat) {
                      focusScope.toggled = false;
                  }
              }
      
              RowLayout {
                  anchors.centerIn: parent
      
                  Button {
                      id: penButton
                      text: qsTr("Pen")
                      highlighted: !focusScope.toggled
                  }
                  Button {
                      id: eyedropperButton
                      text: qsTr("Eyedropper")
                      highlighted: focusScope.toggled
                  }
              }
          }
      }
      

      The idea is that holding the Alt key down will toggle between two "modes". The mode is indicated by a highlighted button.

      Try switching between the buttons. Now open the menu by clicking the "File" button. The menu will receive focus and the focus scope will lose it. If you then close the menu and try to switch between the buttons again, it won't work because the focus scope never regained focus (the root item now has it).

      In this thread, Andrew said that restoring focus to the contentItem of ApplicationWindow would make this work, so we should try to do that.

      Attachments

        Issue Links

          Activity

            People

              mitch_curtis Mitch Curtis
              mitch_curtis Mitch Curtis
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: