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

OS X Bug where keypresses are wrongly routed in a QStackedWidget with NativeWindow widget and QTextEdit

    XMLWordPrintable

Details

    • macOS
    • 894983bea2314c2251a10b0924259a6a58c996ef

    Description

      I've got a QStackedWidget with two child widgets. One is a QGLWidget, the other a QTextEdit.

      I can click the QTextEdit and type normally, then I switch to the other widget and back and text input has broken.

      Some characters work, eg 'q' but others eg 'w' do not. What's more I can see the menu bar flashing when I press q. Q has a menu action!

      I'm debugging Qt source and sure enough in the working state, my QTextEdit gets keyPressEvents as expected. NSWindow sendEvent -> QCocoaView keyDown:

      0 MyInputWidget::keyPressEvent MyInputWidget.cpp 115 0x101715e37
      1 QWidget::event qwidget.cpp 8422 0x1076927ef
      2 QFrame::event qframe.cpp 557 0x107b02f55
      3 QAbstractScrollArea::event qabstractscrollarea.cpp 996 0x107bb5177
      4 QTextEdit::event qtextedit.cpp 1070 0x107b97efd
      5 QApplicationPrivate::notify_helper qapplication.cpp 4562 0x10761f665
      6 QApplication::notify qapplication.cpp 4003 0x107627b15
      7 MyQApplication::notify MyQApplication.cpp 278 0x1010c9f64
      8 QCoreApplication::notifyInternal qcoreapplication.cpp 949 0x108c56310
      9 QCoreApplication::sendSpontaneousEvent qcoreapplication.h 234 0x107584ed7
      10 qt_sendSpontaneousEvent qapplication.cpp 5560 0x10761c72b
      11 QKeyMapper::sendKeyEvent qkeymapper_mac.cpp 1014 0x1076c60c0
      12 QKeyMapperPrivate::translateKeyEvent qkeymapper_mac.cpp 886 0x1076c760d
      13 qt_dispatchKeyEvent qt_cocoa_helpers_mac.mm 839 0x1075ae40b
      14 -[QCocoaView keyDown:] qcocoaview_mac.mm 935 0x10759ca49
      15 -[NSWindow sendEvent:] 0x7fff8c5647ac
      16 -[QCocoaWindow sendEvent:] qcocoasharedwindowmethods_mac_p.h 183 0x1075a2338
      17 -[NSApplication sendEvent:] 0x7fff8c4fda55
      18 -[QNSApplication sendEvent:] qcocoaapplication_mac.mm 186 0x1075a945a
      19 -[NSApplication run] 0x7fff8c4940c6
      20 QEventDispatcherMac::processEvents qeventdispatcher_mac.mm 615 0x1075b737e
      21 QEventLoop::processEvents qeventloop.cpp 149 0x108c543d4
      22 QEventLoop::exec qeventloop.cpp 204 0x108c54814
      23 QCoreApplication::exec qcoreapplication.cpp 1221 0x108c59d82

      In the broken state, the keys which do make it to the QTextEdit::keyPressEvent have a different stack, and the events are now routed via NSWindow keyDown -> NSWindow keyDown -> NSMenu performKeyEquivalent:

      0 MyInputWidget::keyPressEvent MyInputWidget.cpp 115 0x101715e37
      1 QWidget::event qwidget.cpp 8422 0x1076927ef
      2 QFrame::event qframe.cpp 557 0x107b02f55
      3 QAbstractScrollArea::event qabstractscrollarea.cpp 996 0x107bb5177
      4 QTextEdit::event qtextedit.cpp 1070 0x107b97efd
      5 QApplicationPrivate::notify_helper qapplication.cpp 4562 0x10761f665
      6 QApplication::notify qapplication.cpp 4003 0x107627b15
      7 MyQApplication::notify MyQApplication.cpp 278 0x1010c9f64
      8 QCoreApplication::notifyInternal qcoreapplication.cpp 949 0x108c56310
      9 QCoreApplication::sendSpontaneousEvent qcoreapplication.h 234 0x107584ed7
      10 qt_sendSpontaneousEvent qapplication.cpp 5560 0x10761c72b
      11 QKeyMapper::sendKeyEvent qkeymapper_mac.cpp 1014 0x1076c60c0
      12 QKeyMapperPrivate::translateKeyEvent qkeymapper_mac.cpp 886 0x1076c760d
      13 qt_dispatchKeyEvent qt_cocoa_helpers_mac.mm 839 0x1075ae40b
      14 -[QCocoaMenu menuHasKeyEquivalent:forEvent:target:action:] qcocoamenu_mac.mm 189 0x1075ff873
      15 -[NSMenu _performKeyEquivalentWithDelegate:] 0x7fff8c60575b
      16 -[NSMenu _performKeyEquivalentWithDelegate:] 0x7fff8c6059b6
      17 -[NSMenu performKeyEquivalent:] 0x7fff8c605452
      18 -[NSApplication _handleKeyEquivalent:] 0x7fff8c604175
      19 -[NSWindow keyDown:] 0x7fff8cb2fb82
      20 -[NSWindow sendEvent:] 0x7fff8c5647ac
      21 -[QCocoaWindow sendEvent:] qcocoasharedwindowmethods_mac_p.h 183 0x1075a2338
      22 -[NSApplication sendEvent:] 0x7fff8c4fda55
      23 -[QNSApplication sendEvent:] qcocoaapplication_mac.mm 186 0x1075a945a
      24 -[NSApplication run] 0x7fff8c4940c6
      25 QEventDispatcherMac::processEvents qeventdispatcher_mac.mm 615 0x1075b737e
      26 QEventLoop::processEvents qeventloop.cpp 149 0x108c543d4
      27 QEventLoop::exec qeventloop.cpp 204 0x108c54814
      28 QCoreApplication::exec qcoreapplication.cpp 1221 0x108c59d82

      I've checked during MyInputWidget::keyPressEvent and MyInputWidget is indeed QApplication::focusWidget() in both cases.

      If I add an event filter, I can see that the KeyPresses are being routed correctly when I switch to the QGLWidget page, but not when I switch to the QTextEdit page (they are sent to the NSMenu

      Attachments

        1. main.cpp
          0.3 kB
        2. QTBUG-34371.patch
          0.6 kB
        3. testwidget.cpp
          0.9 kB
        4. testwidget.h
          0.3 kB

        Activity

          People

            sgaist Samuel Gaist
            sipickles Simon Pickles
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: