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

macOS: modifier key does not switch between copy/move actions when dragging to file manager

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Reported
    • Priority: P2: Important
    • Resolution: Unresolved
    • Affects Version/s: 5.12
    • Fix Version/s: None
    • Component/s: GUI: Drag and Drop
    • Labels:
      None
    • Environment:
      macOS 10.15.7
      Qt 5.15.2
    • Platform/s:
      macOS

      Description

      On macOS drag action to file manager (Desktop or Finder) does not switch between copy and move via Command key. It used to work in Qt4 and stopped working in Qt5.

      To reproduce:

      1. Clone draggabletext example and add two lines to set mime urls:

      --- dragwidget-orig.cpp 2021-12-27 15:01:07.620073838 +0200
      +++ dragwidget.cpp      2021-12-27 15:01:37.427875858 +0200
      @@ -159,6 +159,8 @@ void DragWidget::mousePressEvent(QMouseE
           mimeData->setText(child->text());
           mimeData->setData(hotSpotMimeDataKey(),
                             QByteArray::number(hotSpot.x()) + ' ' + QByteArray::number(hotSpot.y()));
      +    if (child->text().startsWith("file:///"))
      +        mimeData->setUrls(QList<QUrl>() << QUrl(child->text()));
      
           qreal dpr = window()->windowHandle()->devicePixelRatio();
           QPixmap pixmap(child->size() * dpr);
      

      2. Build and run the app.
      3. Drag any file (file path should not contain whitespace) from Finder to the main window. A new file:///path/to/file.txt label will appear.
      4. Create a new directory in Finder.
      5. Drag file:///path/to/file.txt label to that new directory but do not release the mouse. Try holding/releasing Command key on the keyboard.

      Expected behavior:

      Mouse cursor should change between normal pointer and pointer with a green circle with a plus sign. Accordingly, when mouse released, the file should be moved or copied to the new location.

      Actual behavior:

      Mouse cursor does not change. File is always moved.

      Same code works on Linux as expected. I can switch between copy and move action by holding a Ctrl key.

        Attachments

        1. copy.png
          12 kB
          Sergey Vlasov
        2. drag.png
          222 kB
          Sergey Vlasov
        3. draggabletext.zip
          9 kB
          Sergey Vlasov
        For Gerrit Dashboard: QTBUG-99471
        # Subject Branch Project Status CR V

          Activity

            People

            Assignee:
            tpochep Timur Pocheptsov
            Reporter:
            svlasov Sergey Vlasov
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:

                Gerrit Reviews