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 1.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.
  • 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 Online
        JonBJ Online
        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 Online
              Christian EhrlicherC Online
              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 Online
                  Christian EhrlicherC Online
                  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 Online
                    JonBJ Online
                    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 Online
                        JonBJ Online
                        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