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

Bookkeeping for QApplicationPrivate::focus_window broken on Mac after showing/dismissing QMenu

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • 5.4.0 RC
    • 5.2.1
    • GUI: Window management
    • None
    • OSX 10.8.5 XCode/QtCreator
    • macOS
    • a2ce7e6a6f0f5c638aaa644255e9352eb91b57d6

    Description

      On Windows, QMenu never becomes active but on Mac it does. As a result, on its way out, QApplicationPrivate::focus_window gets cleared by the QWindow destructor for QMenu, leaving the app in a limbo afterwards that shortcuts in the menu bar will always be the one activated, regardless what QWidget actually has the focus. The workaround is to switch to another app then come back.

      Attached please find a simple app that repros the problem.

      Repro steps:
      0) before start, first copy some random text to the clipboard so that we have something to paste into line edit with
      1) launched the sample app, the read-only line edit at the top shows the focusWindow the app currently knows about
      2) right click (or Ctrl+Click) to bring up the context menu
      3) dismiss the context menu

      Notice that on Windows the focus window does not change through out the process. But on Mac however, focus window is updated as soon as the menu shows up, and becomes 0x0 when the menu is dismissed.

      Once in this state, if you now try to paste into the line edit at the bottom using Ctrl/Cmd+V, what gets pasted won't be from the clipboard as one would expect but rather from the "Global Paste" menu item of the menu bar.

      This is because with focus_widget being 0, qApp->focusObject() in menuHasKeyEquivalent in qcocoamenu.mm will always return 0, so the app doesn't think there's a focus widget it needs to consult so it would just go ahead and activate the shortcut in the menubar...

      I ran into the issue on Mac with 5.2.1, but it may exist in 5.x versions prior.

      Attachments

        1. focusWindow.tar.gz
          4 kB
          Pinyen Chen
        2. qtbug-38707.patch
          0.9 kB
          Pinyen Chen

        Issue Links

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

          Activity

            People

              sorvig Morten Sørvig
              bienur Pinyen Chen
              Votes:
              1 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes