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

Popups should restore focus to the contentItem of ApplicationWindow upon closing



    • Type: Bug
    • Status: Closed
    • Priority: P2: Important
    • Resolution: Done
    • Affects Version/s: 5.7
    • Fix Version/s: 5.7.0 RC
    • Component/s: Quick: Controls 2
    • Labels:
    • Commits:


      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.


        No reviews matched the request. Check your Options in the drop-down menu of this sections header.



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


              • Created:

                Gerrit Reviews

                There are no open Gerrit changes