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

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • 6.5.0 Beta1
    • 5.12
    • GUI: Drag and Drop
    • None
    • macOS 10.15.7
      Qt 5.15.2
    • macOS
    • 4332cb3134 (qt/qtbase/dev) 4332cb3134 (qt/tqtc-qtbase/dev), 7740ac36d (dev), c39a944e7 (6.9), 155e81418 (6.8)

    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
          copy.png
          12 kB
        2. drag.png
          drag.png
          222 kB
        3. draggabletext.zip
          9 kB

        Issue Links

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

          Activity

            People

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

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes