Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Issue with drag and drop
Forum Updated to NodeBB v4.3 + New Features

Issue with drag and drop

Scheduled Pinned Locked Moved Solved General and Desktop
18 Posts 4 Posters 2.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Christian EhrlicherC Christian Ehrlicher

    Works also fine with Qt6.6 (from git) on windows (used the same main.cpp as @JoeCFD):

    ...
    dragMoveEvent:  true
    Drag move!!!
    dragMoveEvent:  true
    Drop!!!
    dropEvent:  QList(QUrl("file:///C:/Users/Chris/Downloads/test.html"))
    Dropped file: "C:/Users/Chris/Downloads/test.html"
    
    Cobra91151C Offline
    Cobra91151C Offline
    Cobra91151
    wrote on last edited by Cobra91151
    #5

    @Christian-Ehrlicher

    Ok. I will create a small example program to find what is causing such issue on my system and replay later.
    Thanks.

    1 Reply Last reply
    0
    • Christian EhrlicherC Christian Ehrlicher

      Works also fine with Qt6.6 (from git) on windows (used the same main.cpp as @JoeCFD):

      ...
      dragMoveEvent:  true
      Drag move!!!
      dragMoveEvent:  true
      Drop!!!
      dropEvent:  QList(QUrl("file:///C:/Users/Chris/Downloads/test.html"))
      Dropped file: "C:/Users/Chris/Downloads/test.html"
      
      Cobra91151C Offline
      Cobra91151C Offline
      Cobra91151
      wrote on last edited by Cobra91151
      #6

      @Christian-Ehrlicher

      I tried using a small example program but still the same issue is present. It does not call any of drag/drop events. This time I used the Qt 5.9.9, Qt 5.15.9 and Qt 6.4.3.

      DragAndDropExample.pro:

      QT       += core gui
      
      greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
      
      CONFIG += c++17
      
      # You can make your code fail to compile if it uses deprecated APIs.
      # In order to do so, uncomment the following line.
      #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
      
      CONFIG(debug, debug|release) {
          DESTDIR = $$OUT_PWD/debug
      } else {
          DESTDIR = $$OUT_PWD/release
      }
      
      MOC_DIR = ./resources/moc
      OBJECTS_DIR = ./resources/objects
      RCC_DIR = ./resources/resource
      
      SOURCES += \
          appqframe.cpp \
          main.cpp \
          mydialog.cpp
      
      HEADERS += \
          appqframe.h \
          mydialog.h
      
      # Default rules for deployment.
      #qnx: target.path = /tmp/$${TARGET}/bin
      #else: unix:!android: target.path = /opt/$${TARGET}/bin
      #!isEmpty(target.path): INSTALLS += target
      

      AppQFrame.h:

      #ifndef APPQFRAME_H
      #define APPQFRAME_H
      
      #include <QWidget>
      #include <QFrame>
      #include <QMouseEvent>
      #include <QEvent>
      #include <QMimeData>
      #include <QDebug>
      #include <QDrag>
      #include <QDragMoveEvent>
      #include <QDragEnterEvent>
      #include <QDropEvent>
      
      class AppQFrame : public QFrame
      {
          Q_OBJECT
      public:
          explicit AppQFrame(QWidget *parent);
      
      signals:
          void mouseMove(QMouseEvent *event);
          void mouseClick(QMouseEvent *event);
          void mouseRelease(QMouseEvent *event);
          void mouseEnter();
          void mouseLeave();
      
      protected:
          void mouseMoveEvent(QMouseEvent *event) override;
          void mousePressEvent(QMouseEvent *event) override;
          void mouseReleaseEvent(QMouseEvent *event) override;
          bool event(QEvent *event) override;
          void dragMoveEvent(QDragMoveEvent *event) override;
          void dragEnterEvent(QDragEnterEvent *event) override;
          void dropEvent(QDropEvent *event) override;
      };
      
      #endif // APPQFRAME_H
      

      AppQFrame.cpp:

      #include "appqframe.h"
      
      AppQFrame::AppQFrame(QWidget *parent) : QFrame(parent)
      {
      
      }
      
      void AppQFrame::mouseMoveEvent(QMouseEvent *event)
      {
          emit mouseMove(event);
          QWidget::mouseMoveEvent(event);
      }
      
      void AppQFrame::mousePressEvent(QMouseEvent *event)
      {
          emit mouseClick(event);
          QWidget::mousePressEvent(event);
      }
      
      void AppQFrame::mouseReleaseEvent(QMouseEvent *event)
      {
          emit mouseRelease(event);
          QWidget::mouseReleaseEvent(event);
      }
      
      bool AppQFrame::event(QEvent *event)
      {
          switch (event->type()) {
              case QEvent::HoverEnter:
                   emit mouseEnter();
                  break;
              case QEvent::HoverLeave:
                   emit mouseLeave();
                  break;
              case QEvent::DragEnter:
                   qDebug() << "Drag enter!!!";
                  break;
              case QEvent::DragLeave:
                   qDebug() << "Drag leave!!!";
                  break;
              case QEvent::DragMove:
                   qDebug() << "Drag move!!!";
                  break;
              case QEvent::DragResponse:
                   qDebug() << "Drag response!!!";
                  break;
              case QEvent::Drop:
                   qDebug() << "Drop!!!";
                  break;
              case QEvent::AcceptDropsChange:
                   qDebug() << "Accept Drops Change!!!";
                  break;
              default:
                  break;
          }
      
          return QWidget::event(event);
      }
      
      void AppQFrame::dragMoveEvent(QDragMoveEvent *event)
      {
          qDebug() << "dragMoveEvent: " << event->mimeData()->hasUrls();
      
          if (event->mimeData()->hasUrls()) {
              event->acceptProposedAction();
              event->accept();
          }
      }
      
      void AppQFrame::dragEnterEvent(QDragEnterEvent *event)
      {
          qDebug() << "dragEnterEvent: " << event->mimeData()->hasUrls();
      
          if (event->mimeData()->hasUrls()) {
              event->acceptProposedAction();
              event->accept();
          }
      }
      
      void AppQFrame::dropEvent(QDropEvent *event)
      {
          qDebug() << "dropEvent: " << event->mimeData()->urls();
          event->setDropAction(Qt::CopyAction);
      
          foreach (const QUrl &url, event->mimeData()->urls()) {
              QString fileName = url.toLocalFile();
              qDebug() << "Dropped file:" << fileName;
          }
      }
      

      main.cpp

      #include <QApplication>
      #include "mydialog.h"
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
          MyDialog w;
          w.show();
          return a.exec();
      }
      

      mydialog.h

      #ifndef MYDIALOG_H
      #define MYDIALOG_H
      
      #include <QDialog>
      #include <QHBoxLayout>
      #include "appqframe.h"
      
      class MyDialog : public QDialog
      {
          Q_OBJECT
      
      public:
          MyDialog(QWidget *parent = nullptr);
          ~MyDialog();
      };
      #endif // MYDIALOG_H
      

      mydialog.cpp

      #include "mydialog.h"
      
      MyDialog::MyDialog(QWidget *parent)
          : QDialog(parent)
      {
          setWindowTitle(QObject::tr("Feedback"));
          setMinimumSize(480, 610);
          setWindowModality(Qt::ApplicationModal);
          setWindowFlags(Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint | Qt::WindowCloseButtonHint);
          setAcceptDrops(true);
          AppQFrame *attachmentsFrame = new AppQFrame(this);
          attachmentsFrame->setFixedSize(550, 390);
          attachmentsFrame->setObjectName("inputItem");
          attachmentsFrame->setStyleSheet("border: 0.5px dashed #000000; margin: 10px;");
          attachmentsFrame->setAcceptDrops(true);
          attachmentsFrame->setMouseTracking(true);
          attachmentsFrame->setAttribute(Qt::WA_Hover);
          attachmentsFrame->setVisible(true);
          QHBoxLayout *testLayout = new QHBoxLayout();
          testLayout->addWidget(attachmentsFrame);
          setLayout(testLayout);
      }
      
      MyDialog::~MyDialog()
      {
      }
      

      Screenshot:

      Drag and Drop issue

      It only checks for QEvent::AcceptDropsChange event. Any ideas why it can not accept drag and drop? Thanks.

      JonBJ 1 Reply Last reply
      0
      • Cobra91151C Cobra91151

        @Christian-Ehrlicher

        I tried using a small example program but still the same issue is present. It does not call any of drag/drop events. This time I used the Qt 5.9.9, Qt 5.15.9 and Qt 6.4.3.

        DragAndDropExample.pro:

        QT       += core gui
        
        greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
        
        CONFIG += c++17
        
        # You can make your code fail to compile if it uses deprecated APIs.
        # In order to do so, uncomment the following line.
        #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
        
        CONFIG(debug, debug|release) {
            DESTDIR = $$OUT_PWD/debug
        } else {
            DESTDIR = $$OUT_PWD/release
        }
        
        MOC_DIR = ./resources/moc
        OBJECTS_DIR = ./resources/objects
        RCC_DIR = ./resources/resource
        
        SOURCES += \
            appqframe.cpp \
            main.cpp \
            mydialog.cpp
        
        HEADERS += \
            appqframe.h \
            mydialog.h
        
        # Default rules for deployment.
        #qnx: target.path = /tmp/$${TARGET}/bin
        #else: unix:!android: target.path = /opt/$${TARGET}/bin
        #!isEmpty(target.path): INSTALLS += target
        

        AppQFrame.h:

        #ifndef APPQFRAME_H
        #define APPQFRAME_H
        
        #include <QWidget>
        #include <QFrame>
        #include <QMouseEvent>
        #include <QEvent>
        #include <QMimeData>
        #include <QDebug>
        #include <QDrag>
        #include <QDragMoveEvent>
        #include <QDragEnterEvent>
        #include <QDropEvent>
        
        class AppQFrame : public QFrame
        {
            Q_OBJECT
        public:
            explicit AppQFrame(QWidget *parent);
        
        signals:
            void mouseMove(QMouseEvent *event);
            void mouseClick(QMouseEvent *event);
            void mouseRelease(QMouseEvent *event);
            void mouseEnter();
            void mouseLeave();
        
        protected:
            void mouseMoveEvent(QMouseEvent *event) override;
            void mousePressEvent(QMouseEvent *event) override;
            void mouseReleaseEvent(QMouseEvent *event) override;
            bool event(QEvent *event) override;
            void dragMoveEvent(QDragMoveEvent *event) override;
            void dragEnterEvent(QDragEnterEvent *event) override;
            void dropEvent(QDropEvent *event) override;
        };
        
        #endif // APPQFRAME_H
        

        AppQFrame.cpp:

        #include "appqframe.h"
        
        AppQFrame::AppQFrame(QWidget *parent) : QFrame(parent)
        {
        
        }
        
        void AppQFrame::mouseMoveEvent(QMouseEvent *event)
        {
            emit mouseMove(event);
            QWidget::mouseMoveEvent(event);
        }
        
        void AppQFrame::mousePressEvent(QMouseEvent *event)
        {
            emit mouseClick(event);
            QWidget::mousePressEvent(event);
        }
        
        void AppQFrame::mouseReleaseEvent(QMouseEvent *event)
        {
            emit mouseRelease(event);
            QWidget::mouseReleaseEvent(event);
        }
        
        bool AppQFrame::event(QEvent *event)
        {
            switch (event->type()) {
                case QEvent::HoverEnter:
                     emit mouseEnter();
                    break;
                case QEvent::HoverLeave:
                     emit mouseLeave();
                    break;
                case QEvent::DragEnter:
                     qDebug() << "Drag enter!!!";
                    break;
                case QEvent::DragLeave:
                     qDebug() << "Drag leave!!!";
                    break;
                case QEvent::DragMove:
                     qDebug() << "Drag move!!!";
                    break;
                case QEvent::DragResponse:
                     qDebug() << "Drag response!!!";
                    break;
                case QEvent::Drop:
                     qDebug() << "Drop!!!";
                    break;
                case QEvent::AcceptDropsChange:
                     qDebug() << "Accept Drops Change!!!";
                    break;
                default:
                    break;
            }
        
            return QWidget::event(event);
        }
        
        void AppQFrame::dragMoveEvent(QDragMoveEvent *event)
        {
            qDebug() << "dragMoveEvent: " << event->mimeData()->hasUrls();
        
            if (event->mimeData()->hasUrls()) {
                event->acceptProposedAction();
                event->accept();
            }
        }
        
        void AppQFrame::dragEnterEvent(QDragEnterEvent *event)
        {
            qDebug() << "dragEnterEvent: " << event->mimeData()->hasUrls();
        
            if (event->mimeData()->hasUrls()) {
                event->acceptProposedAction();
                event->accept();
            }
        }
        
        void AppQFrame::dropEvent(QDropEvent *event)
        {
            qDebug() << "dropEvent: " << event->mimeData()->urls();
            event->setDropAction(Qt::CopyAction);
        
            foreach (const QUrl &url, event->mimeData()->urls()) {
                QString fileName = url.toLocalFile();
                qDebug() << "Dropped file:" << fileName;
            }
        }
        

        main.cpp

        #include <QApplication>
        #include "mydialog.h"
        
        int main(int argc, char *argv[])
        {
            QApplication a(argc, argv);
            MyDialog w;
            w.show();
            return a.exec();
        }
        

        mydialog.h

        #ifndef MYDIALOG_H
        #define MYDIALOG_H
        
        #include <QDialog>
        #include <QHBoxLayout>
        #include "appqframe.h"
        
        class MyDialog : public QDialog
        {
            Q_OBJECT
        
        public:
            MyDialog(QWidget *parent = nullptr);
            ~MyDialog();
        };
        #endif // MYDIALOG_H
        

        mydialog.cpp

        #include "mydialog.h"
        
        MyDialog::MyDialog(QWidget *parent)
            : QDialog(parent)
        {
            setWindowTitle(QObject::tr("Feedback"));
            setMinimumSize(480, 610);
            setWindowModality(Qt::ApplicationModal);
            setWindowFlags(Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint | Qt::WindowCloseButtonHint);
            setAcceptDrops(true);
            AppQFrame *attachmentsFrame = new AppQFrame(this);
            attachmentsFrame->setFixedSize(550, 390);
            attachmentsFrame->setObjectName("inputItem");
            attachmentsFrame->setStyleSheet("border: 0.5px dashed #000000; margin: 10px;");
            attachmentsFrame->setAcceptDrops(true);
            attachmentsFrame->setMouseTracking(true);
            attachmentsFrame->setAttribute(Qt::WA_Hover);
            attachmentsFrame->setVisible(true);
            QHBoxLayout *testLayout = new QHBoxLayout();
            testLayout->addWidget(attachmentsFrame);
            setLayout(testLayout);
        }
        
        MyDialog::~MyDialog()
        {
        }
        

        Screenshot:

        Drag and Drop issue

        It only checks for QEvent::AcceptDropsChange event. Any ideas why it can not accept drag and drop? Thanks.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #7

        @Cobra91151
        A couple of thoughts.

        One tiny thing to rule out: Windows itself does not allow drag/drop between applications running elevated and those not. Make sure both Explorer and your application are running as the same, non-elevated user?

        Second I would try reducing your application to the bare minimum to test. Get rid of QDialog, get rid of that one's setAcceptDrops(true), get rid of setWindowModality(Qt::ApplicationModal), get rid of your AppQFrame. A simple (sub-classed) QWidget, with nothing in it, should be enough to test the basics. After that, it's a bit long, but I think the example at https://wiki.qt.io/Drag_and_Drop_of_files should be copyable for you to test?

        Cobra91151C 2 Replies Last reply
        3
        • JonBJ JonB

          @Cobra91151
          A couple of thoughts.

          One tiny thing to rule out: Windows itself does not allow drag/drop between applications running elevated and those not. Make sure both Explorer and your application are running as the same, non-elevated user?

          Second I would try reducing your application to the bare minimum to test. Get rid of QDialog, get rid of that one's setAcceptDrops(true), get rid of setWindowModality(Qt::ApplicationModal), get rid of your AppQFrame. A simple (sub-classed) QWidget, with nothing in it, should be enough to test the basics. After that, it's a bit long, but I think the example at https://wiki.qt.io/Drag_and_Drop_of_files should be copyable for you to test?

          Cobra91151C Offline
          Cobra91151C Offline
          Cobra91151
          wrote on last edited by
          #8

          @JonB

          I have tried it on Windows 11, Windows 10, Windows 8.1 and Windows 7 VMs and on my laptop (Windows 10) still the same issue exists.

          Now, I will try your suggestions and reply. Thanks.

          1 Reply Last reply
          0
          • JonBJ JonB

            @Cobra91151
            A couple of thoughts.

            One tiny thing to rule out: Windows itself does not allow drag/drop between applications running elevated and those not. Make sure both Explorer and your application are running as the same, non-elevated user?

            Second I would try reducing your application to the bare minimum to test. Get rid of QDialog, get rid of that one's setAcceptDrops(true), get rid of setWindowModality(Qt::ApplicationModal), get rid of your AppQFrame. A simple (sub-classed) QWidget, with nothing in it, should be enough to test the basics. After that, it's a bit long, but I think the example at https://wiki.qt.io/Drag_and_Drop_of_files should be copyable for you to test?

            Cobra91151C Offline
            Cobra91151C Offline
            Cobra91151
            wrote on last edited by Cobra91151
            #9

            @JonB

            I tried a simple sub-classed QWidget but it still does not work. For some reason it blocks the drag and drop, no debug logs from these events, nothing is printed to the console. Only mouse events and QEvent::AcceptDropsChange is printed.

            I have built Qt by my own, I think some library which is required for drag and drop is missing on my system. I will try the official Qt build from Maintenance Tool to verify how it works.

            JonBJ 1 Reply Last reply
            0
            • Cobra91151C Cobra91151

              @JonB

              I tried a simple sub-classed QWidget but it still does not work. For some reason it blocks the drag and drop, no debug logs from these events, nothing is printed to the console. Only mouse events and QEvent::AcceptDropsChange is printed.

              I have built Qt by my own, I think some library which is required for drag and drop is missing on my system. I will try the official Qt build from Maintenance Tool to verify how it works.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #10

              @Cobra91151
              OK, I don't know. Did you actually copy/try that https://wiki.qt.io/Drag_and_Drop_of_files as-is so we know the code should be as they intend?

              Cobra91151C 1 Reply Last reply
              0
              • JonBJ JonB

                @Cobra91151
                OK, I don't know. Did you actually copy/try that https://wiki.qt.io/Drag_and_Drop_of_files as-is so we know the code should be as they intend?

                Cobra91151C Offline
                Cobra91151C Offline
                Cobra91151
                wrote on last edited by Cobra91151
                #11

                @JonB

                I tried official Qt build with this small example, still the same issue. https://wiki.qt.io/Drag_and_Drop_of_files It does not call any of drag or drop events. It should call the drag/drop events without any code just print it to console using qDebug?

                setAcceptDrops(true);
                qDebug() << "acceptDrops: " << acceptDrops();
                

                Returns:
                acceptDrops: true

                But it still does not allow to drop anything, the cursor is blocking, which means it ignores the drag and drop operation even though I set it to setAcceptDrops.
                I think, it should be activated somewhere to accept drops? Or why it blocks the drag and drop?

                1 Reply Last reply
                0
                • Christian EhrlicherC Christian Ehrlicher

                  Works also fine with Qt6.6 (from git) on windows (used the same main.cpp as @JoeCFD):

                  ...
                  dragMoveEvent:  true
                  Drag move!!!
                  dragMoveEvent:  true
                  Drop!!!
                  dropEvent:  QList(QUrl("file:///C:/Users/Chris/Downloads/test.html"))
                  Dropped file: "C:/Users/Chris/Downloads/test.html"
                  
                  Cobra91151C Offline
                  Cobra91151C Offline
                  Cobra91151
                  wrote on last edited by
                  #12

                  @JoeCFD @Christian-Ehrlicher @JonB

                  Finally, I found the root of this issue. The issue is with administrative privileges. When my program has administrative privileges then for some reason the drag and drop operation fails and Qt widget does not accept it and ignores it. When I remove the admin privileges, then it works well.

                  Log:

                  dragEnterEvent:  true
                  dragMoveEvent:  true
                  dragMoveEvent:  true
                  dragMoveEvent:  true
                  dragMoveEvent:  true
                  dragMoveEvent:  true
                  dragMoveEvent:  true
                  dragMoveEvent:  true
                  dragMoveEvent:  true
                  dragMoveEvent:  true
                  dragMoveEvent:  true
                  dragMoveEvent:  true
                  dragMoveEvent:  true
                  dragMoveEvent:  true
                  dragMoveEvent:  true
                  dragMoveEvent:  true
                  dragMoveEvent:  true
                  dragMoveEvent:  true
                  dragMoveEvent:  true
                  dragMoveEvent:  true
                  dragMoveEvent:  true
                  dragMoveEvent:  true
                  dragMoveEvent:  true
                  dragMoveEvent:  true
                  dragMoveEvent:  true
                  dragMoveEvent:  true
                  dragMoveEvent:  true
                  dragMoveEvent:  true
                  dragMoveEvent:  true
                  dragMoveEvent:  true
                  dragMoveEvent:  true
                  dragMoveEvent:  true
                  dragMoveEvent:  true
                  dragMoveEvent:  true
                  dragMoveEvent:  true
                  dragMoveEvent:  true
                  dragMoveEvent:  true
                  dragMoveEvent:  true
                  dragMoveEvent:  true
                  dragMoveEvent:  true
                  dragMoveEvent:  true
                  dragMoveEvent:  true
                  dragMoveEvent:  true
                  dragMoveEvent:  true
                  dragMoveEvent:  true
                  dragMoveEvent:  true
                  dropEvent:  (QUrl("file:///C:/Users/cobra/Documents/Projects/CPP/build-DragAndDropExample-Desktop_Qt_5_15_2_MSVC2019_32bit-Debug/debug/opengl32sw.dll"))
                  Dropped file: "C:/Users/cobra/Documents/Projects/CPP/build-DragAndDropExample-Desktop_Qt_5_15_2_MSVC2019_32bit-Debug/debug/opengl32sw.dll"
                  

                  I have found the similar issue here:
                  https://forum.qt.io/topic/131155/qt-applications-cannot-drag-and-drop-files-when-running-under-windows-with-administrator-rights/13

                  For example, I need my program to have admin privileges and allow the drag and drop. Now, the question is how to fix such issue? Thank you.

                  Christian EhrlicherC JonBJ 2 Replies Last reply
                  0
                  • Cobra91151C Cobra91151

                    @JoeCFD @Christian-Ehrlicher @JonB

                    Finally, I found the root of this issue. The issue is with administrative privileges. When my program has administrative privileges then for some reason the drag and drop operation fails and Qt widget does not accept it and ignores it. When I remove the admin privileges, then it works well.

                    Log:

                    dragEnterEvent:  true
                    dragMoveEvent:  true
                    dragMoveEvent:  true
                    dragMoveEvent:  true
                    dragMoveEvent:  true
                    dragMoveEvent:  true
                    dragMoveEvent:  true
                    dragMoveEvent:  true
                    dragMoveEvent:  true
                    dragMoveEvent:  true
                    dragMoveEvent:  true
                    dragMoveEvent:  true
                    dragMoveEvent:  true
                    dragMoveEvent:  true
                    dragMoveEvent:  true
                    dragMoveEvent:  true
                    dragMoveEvent:  true
                    dragMoveEvent:  true
                    dragMoveEvent:  true
                    dragMoveEvent:  true
                    dragMoveEvent:  true
                    dragMoveEvent:  true
                    dragMoveEvent:  true
                    dragMoveEvent:  true
                    dragMoveEvent:  true
                    dragMoveEvent:  true
                    dragMoveEvent:  true
                    dragMoveEvent:  true
                    dragMoveEvent:  true
                    dragMoveEvent:  true
                    dragMoveEvent:  true
                    dragMoveEvent:  true
                    dragMoveEvent:  true
                    dragMoveEvent:  true
                    dragMoveEvent:  true
                    dragMoveEvent:  true
                    dragMoveEvent:  true
                    dragMoveEvent:  true
                    dragMoveEvent:  true
                    dragMoveEvent:  true
                    dragMoveEvent:  true
                    dragMoveEvent:  true
                    dragMoveEvent:  true
                    dragMoveEvent:  true
                    dragMoveEvent:  true
                    dragMoveEvent:  true
                    dropEvent:  (QUrl("file:///C:/Users/cobra/Documents/Projects/CPP/build-DragAndDropExample-Desktop_Qt_5_15_2_MSVC2019_32bit-Debug/debug/opengl32sw.dll"))
                    Dropped file: "C:/Users/cobra/Documents/Projects/CPP/build-DragAndDropExample-Desktop_Qt_5_15_2_MSVC2019_32bit-Debug/debug/opengl32sw.dll"
                    

                    I have found the similar issue here:
                    https://forum.qt.io/topic/131155/qt-applications-cannot-drag-and-drop-files-when-running-under-windows-with-administrator-rights/13

                    For example, I need my program to have admin privileges and allow the drag and drop. Now, the question is how to fix such issue? Thank you.

                    Christian EhrlicherC Offline
                    Christian EhrlicherC Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by
                    #13

                    @Cobra91151 said in Issue with drag and drop:

                    Finally, I found the root of this issue. The issue is with administrative privileges. When my program has administrative privileges then for some reason the drag and drop operation fails and Qt widget does not accept it and ignores it.

                    @JonB already told you this some time ago:

                    One tiny thing to rule out: Windows itself does not allow drag/drop between applications running elevated and those not. Make sure both Explorer and your application are running as the same, non-elevated user?

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    Cobra91151C 1 Reply Last reply
                    2
                    • Christian EhrlicherC Christian Ehrlicher

                      @Cobra91151 said in Issue with drag and drop:

                      Finally, I found the root of this issue. The issue is with administrative privileges. When my program has administrative privileges then for some reason the drag and drop operation fails and Qt widget does not accept it and ignores it.

                      @JonB already told you this some time ago:

                      One tiny thing to rule out: Windows itself does not allow drag/drop between applications running elevated and those not. Make sure both Explorer and your application are running as the same, non-elevated user?

                      Cobra91151C Offline
                      Cobra91151C Offline
                      Cobra91151
                      wrote on last edited by
                      #14

                      @Christian-Ehrlicher said in Issue with drag and drop:

                      @JonB already told you this some time ago:

                      One tiny thing to rule out: Windows itself does not allow drag/drop between applications running elevated and those not. Make sure both Explorer and your application are running as the same, non-elevated user?

                      So, how to allow drag/drop between application running elevated and non-elevated user? Is it possible using Win API and Qt? Why Qt just ignores it and not set the debug message: "this kind of drag/drop opration is not allowed"? Thanks.

                      Christian EhrlicherC 1 Reply Last reply
                      0
                      • Cobra91151C Cobra91151

                        @Christian-Ehrlicher said in Issue with drag and drop:

                        @JonB already told you this some time ago:

                        One tiny thing to rule out: Windows itself does not allow drag/drop between applications running elevated and those not. Make sure both Explorer and your application are running as the same, non-elevated user?

                        So, how to allow drag/drop between application running elevated and non-elevated user? Is it possible using Win API and Qt? Why Qt just ignores it and not set the debug message: "this kind of drag/drop opration is not allowed"? Thanks.

                        Christian EhrlicherC Offline
                        Christian EhrlicherC Offline
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on last edited by
                        #15

                        @Cobra91151 said in Issue with drag and drop:

                        Why Qt just ignores it and not set the debug message: "this kind of drag/drop opration is not allowed"?

                        Because, as already said, a drag and drop between apps with different privileges is not allowed - it's not a program thing but windows - so how should the (possible) receiver print something when it does not get notified in any way?

                        There is nothing Qt can do against it. If you find a way feel free to report it.

                        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                        Visit the Qt Academy at https://academy.qt.io/catalog

                        1 Reply Last reply
                        3
                        • Cobra91151C Cobra91151

                          @JoeCFD @Christian-Ehrlicher @JonB

                          Finally, I found the root of this issue. The issue is with administrative privileges. When my program has administrative privileges then for some reason the drag and drop operation fails and Qt widget does not accept it and ignores it. When I remove the admin privileges, then it works well.

                          Log:

                          dragEnterEvent:  true
                          dragMoveEvent:  true
                          dragMoveEvent:  true
                          dragMoveEvent:  true
                          dragMoveEvent:  true
                          dragMoveEvent:  true
                          dragMoveEvent:  true
                          dragMoveEvent:  true
                          dragMoveEvent:  true
                          dragMoveEvent:  true
                          dragMoveEvent:  true
                          dragMoveEvent:  true
                          dragMoveEvent:  true
                          dragMoveEvent:  true
                          dragMoveEvent:  true
                          dragMoveEvent:  true
                          dragMoveEvent:  true
                          dragMoveEvent:  true
                          dragMoveEvent:  true
                          dragMoveEvent:  true
                          dragMoveEvent:  true
                          dragMoveEvent:  true
                          dragMoveEvent:  true
                          dragMoveEvent:  true
                          dragMoveEvent:  true
                          dragMoveEvent:  true
                          dragMoveEvent:  true
                          dragMoveEvent:  true
                          dragMoveEvent:  true
                          dragMoveEvent:  true
                          dragMoveEvent:  true
                          dragMoveEvent:  true
                          dragMoveEvent:  true
                          dragMoveEvent:  true
                          dragMoveEvent:  true
                          dragMoveEvent:  true
                          dragMoveEvent:  true
                          dragMoveEvent:  true
                          dragMoveEvent:  true
                          dragMoveEvent:  true
                          dragMoveEvent:  true
                          dragMoveEvent:  true
                          dragMoveEvent:  true
                          dragMoveEvent:  true
                          dragMoveEvent:  true
                          dragMoveEvent:  true
                          dropEvent:  (QUrl("file:///C:/Users/cobra/Documents/Projects/CPP/build-DragAndDropExample-Desktop_Qt_5_15_2_MSVC2019_32bit-Debug/debug/opengl32sw.dll"))
                          Dropped file: "C:/Users/cobra/Documents/Projects/CPP/build-DragAndDropExample-Desktop_Qt_5_15_2_MSVC2019_32bit-Debug/debug/opengl32sw.dll"
                          

                          I have found the similar issue here:
                          https://forum.qt.io/topic/131155/qt-applications-cannot-drag-and-drop-files-when-running-under-windows-with-administrator-rights/13

                          For example, I need my program to have admin privileges and allow the drag and drop. Now, the question is how to fix such issue? Thank you.

                          JonBJ Offline
                          JonBJ Offline
                          JonB
                          wrote on last edited by JonB
                          #16

                          @Cobra91151 said in Issue with drag and drop:

                          have admin privileges and allow the drag and drop

                          Google Windows have admin privileges and allow the drag and drop if you want to read up about it, e.g. https://jacquesheunis.com/post/dragndrop-admin/

                          It turns out that if you run something “as admin” in Windows, you won’t be able to drag-and-drop files into that program from somewhere else that wasn’t run as admin. This is to prevent so-called “Shatter attacks” which could result in privilege escalation

                          Maybe you will find some "hacks", I don't know. https://www.reddit.com/r/discordapp/comments/l63doo/cant_drag_and_drop_while_running_as_admin/ claims

                          Okay, I just found the fix for it.

                          HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System

                          and change EnableLUA value to 0

                          (Is that disabling UAC to get around it??) Maybe that works and you only care about your own machine?

                          In a word, you're not supposed to do this. Maybe you can make your program not require admin privileges, maybe you could delegate that to a non-UI program you communicate with.

                          Cobra91151C 1 Reply Last reply
                          1
                          • JonBJ JonB

                            @Cobra91151 said in Issue with drag and drop:

                            have admin privileges and allow the drag and drop

                            Google Windows have admin privileges and allow the drag and drop if you want to read up about it, e.g. https://jacquesheunis.com/post/dragndrop-admin/

                            It turns out that if you run something “as admin” in Windows, you won’t be able to drag-and-drop files into that program from somewhere else that wasn’t run as admin. This is to prevent so-called “Shatter attacks” which could result in privilege escalation

                            Maybe you will find some "hacks", I don't know. https://www.reddit.com/r/discordapp/comments/l63doo/cant_drag_and_drop_while_running_as_admin/ claims

                            Okay, I just found the fix for it.

                            HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System

                            and change EnableLUA value to 0

                            (Is that disabling UAC to get around it??) Maybe that works and you only care about your own machine?

                            In a word, you're not supposed to do this. Maybe you can make your program not require admin privileges, maybe you could delegate that to a non-UI program you communicate with.

                            Cobra91151C Offline
                            Cobra91151C Offline
                            Cobra91151
                            wrote on last edited by Cobra91151
                            #17

                            @JonB

                            No need to change the registry values. I have found hack with Notepad (admin privileges) which allows to drap/drop files directly from Windows Explorer to my program with admin privileges. Additionally, I can drop files from another program like Total Commander (with admin privileges) or mine program with admin privileges which has QFileSystemModel (I called it PC Explorer).

                            Screenshot:

                            Notpad admin privileges hack

                            JonBJ 1 Reply Last reply
                            0
                            • Cobra91151C Cobra91151 has marked this topic as solved on
                            • Cobra91151C Cobra91151

                              @JonB

                              No need to change the registry values. I have found hack with Notepad (admin privileges) which allows to drap/drop files directly from Windows Explorer to my program with admin privileges. Additionally, I can drop files from another program like Total Commander (with admin privileges) or mine program with admin privileges which has QFileSystemModel (I called it PC Explorer).

                              Screenshot:

                              Notpad admin privileges hack

                              JonBJ Offline
                              JonBJ Offline
                              JonB
                              wrote on last edited by
                              #18

                              @Cobra91151 said in Issue with drag and drop:

                              No need to change the registry values. I have found hack with Notepad (admin privileges) which allows to drap/drop files directly from Windows Explorer to my program with admin privileges

                              LOL :)

                              1 Reply Last reply
                              1

                              • Login

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • Users
                              • Groups
                              • Search
                              • Get Qt Extensions
                              • Unsolved