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

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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Reported
    • Priority: P3: Somewhat important
    • Resolution: Unresolved
    • Affects Version/s: 5.15.0
    • Fix Version/s: None
    • Labels:
      None
    • Platform/s:
      macOS

      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

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

          Activity

            People

            Assignee:
            qt.team.quick.subscriptions Qt Quick and Widgets Team
            Reporter:
            reneme Rene Meusel
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:

                Gerrit Reviews

                There are no open Gerrit changes