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

Shortcuts not working in popup on Mac

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.12.6, 5.14.1
    • None
    • macOS

    Description

      In attachment you can find a minimal Qt creator project demonstrating the problem.
      If you launch this on Mac and press the QPushButton, a QLineEdit will show as a popup window.
      In this lineEdit you can’t use the ‘select-all’ shortcut.

      The reason for this is that the main mindow has a menu containing also the ‘select-all’ item.
      When you press the shortcut, the menu item is triggered instead of selecting everything in the lineEdit.

      If I understand the Qt code correctly, this should be handled in ‘qtbase-everywhere-src/src/plugins/platforms/cocoa/qcocoansmenu.mm’ inside the menuHasKeyEquivalent function. The comments over here indicate that my lineEdit should get the event instead of triggering the menu item.
      The reason this function doesn’t work, is because the focusObject is not set properly when showing the popup.

      In my example I try setting the focus on the lineEdit and while doing so we come in ‘qtbase-everywhere-src/src/widgets/kernel/qwidget.cpp’ inside the updateFocusChild function. Here we set the lineEdit as the focus_child of each parent widget until we reach the window parent.
      The lineEdit has the Qt::Popup windowFlag set (which includes the Qt::Window flag) and hence setting the focus_child stops at this level. So the lineEdit is not set as the focus_child of the main window.
      So the code of the menu (which is attached to the main mindow) doesn’t work as it requests the focusObject of the main window.

      If I adapt the code in updateFocusChild to also set the focus_child in the parent of a popup, it works. But I’m not sure if this is the right fix…

      Attachments

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

        Activity

          People

            vestbo Tor Arne Vestbø
            dbutijn David Butijn
            Veli-Pekka Heinonen Veli-Pekka Heinonen
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes