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

Setting the focus doesn't set firstResponder correspondingly

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.2.1, 5.3.0 RC1, 5.15.1
    • QPA
    • None
    • OS X 10.9
    • macOS

    Description

      When Qt sets the focus to a widget, the corresponding NSView is not made firstResponder. In the "normal" QWidget application this is no problem, since there is only a single QNSView for each window. It might lead to effects when some widget is forced to be native, but I haven't checked that in detail (it might not be a problem because everything is handled in the Qt-controlled QNSView class). It especially is an issue when embedding a native NSView with QMacCocoaViewContainer.

      When clicking on a QWidget, AppKit automatically changes firstResponder due to the mouse event, but when programmatically setting the focus (e.g. from a menu action), the firstResponder stays at the previous NSView, so that receives and handles key events instead of the focus-QWidget.

      I've attached a little test application. Give the top NSTextField focus, press cmd+L to set the Qt focus to the QTextEdit, type something. Expected: NSTextField loses focus, QTextEdit receives the keys. Actual: NSTextField keeps focus and receives the keys, QTextEdit doesn't receive the keys even though it thinks that it has keyboard focus.

      You can uncomment the two lines in Widget::setFocusToTextEdit() to set the firstResponder correctly, and fix the example.

      Attachments

        For Gerrit Dashboard: QTBUG-39017
        # Subject Branch Project Status CR V

        Activity

          People

            sorvig Morten Sørvig
            con Eike Ziller
            Veli-Pekka Heinonen Veli-Pekka Heinonen
            Votes:
            2 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes