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

QWindow::startSystemMove() does not work with QML DragHandler on macOS

    XMLWordPrintable

Details

    • macOS
    • cdc7bff115c296474ea871549da91de09c3a020d (qt/qtbase/dev) 68eebf175035f7fda11a9aa7ce6436430b2766ea (qt/qtbase/5.15)

    Description

      We were excited that Qt 5.15.0 supports custom window decorations (see this blog post by Johan Helsing). Unfortunately, it did not work out of the box on macOS (10.15 but presumably other versions, too). The blog post's example project also did not work on macOS.

      When using a DragHandler like illustrated below:

      DragHandler {
          onActiveChanged: {
              if (active) {
                  console.log(shareWindow.startSystemMove());
              }
          }
          target: null
      }
      

      ... we see print-outs of false in our console.

      Debugging into the implementation in qcocoawindow.mm we found that NSApp.currentEvent.type is NSEventTypeLeftMouseDragged when used with DragHandler. However, this event type is not specifically handled. The NSEventTypeLeftMouseDragged event type was introduced in macOS 10.12 (see docs).

      The patch below fixed it for us and window dragging worked like a charm:

      diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm
      index 069e9ce845..7d9ca9886b 100644
      --- a/src/plugins/platforms/cocoa/qcocoawindow.mm
      +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm
      @@ -306,6 +306,9 @@ bool QCocoaWindow::startSystemMove()
           case NSEventTypeRightMouseDown:
           case NSEventTypeOtherMouseDown:
           case NSEventTypeMouseMoved:
      +    case NSEventTypeLeftMouseDragged:
      +    case NSEventTypeRightMouseDragged:
      +    case NSEventTypeOtherMouseDragged:
               // The documentation only describes starting a system move
               // based on mouse down events, but move events also work.
               [m_view.window performWindowDragWithEvent:NSApp.currentEvent];
      

      It would be great to have a fix in Qt 5.15.1.

      Attachments

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

        Activity

          People

            vestbo Tor Arne Vestbø
            reneme Rene Meusel
            Votes:
            1 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes