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.
  • J JonB
    26 Aug 2023, 09:20

    @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?

    C Offline
    C Offline
    Cobra91151
    wrote on 26 Aug 2023, 10:59 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.

    J 1 Reply Last reply 26 Aug 2023, 11:07
    0
    • C Cobra91151
      26 Aug 2023, 10:59

      @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.

      J Offline
      J Offline
      JonB
      wrote on 26 Aug 2023, 11:07 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?

      C 1 Reply Last reply 26 Aug 2023, 11:38
      0
      • J JonB
        26 Aug 2023, 11:07

        @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?

        C Offline
        C Offline
        Cobra91151
        wrote on 26 Aug 2023, 11:38 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
        • C Christian Ehrlicher
          25 Aug 2023, 15:49

          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"
          
          C Offline
          C Offline
          Cobra91151
          wrote on 26 Aug 2023, 12:20 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.

          C J 2 Replies Last reply 26 Aug 2023, 12:22
          0
          • C Cobra91151
            26 Aug 2023, 12:20

            @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.

            C Online
            C Online
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on 26 Aug 2023, 12:22 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

            C 1 Reply Last reply 26 Aug 2023, 12:58
            2
            • C Christian Ehrlicher
              26 Aug 2023, 12:22

              @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?

              C Offline
              C Offline
              Cobra91151
              wrote on 26 Aug 2023, 12:58 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.

              C 1 Reply Last reply 26 Aug 2023, 13:08
              0
              • C Cobra91151
                26 Aug 2023, 12:58

                @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.

                C Online
                C Online
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on 26 Aug 2023, 13:08 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
                • C Cobra91151
                  26 Aug 2023, 12:20

                  @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.

                  J Offline
                  J Offline
                  JonB
                  wrote on 26 Aug 2023, 14:17 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.

                  C 1 Reply Last reply 26 Aug 2023, 14:28
                  1
                  • J JonB
                    26 Aug 2023, 14:17

                    @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.

                    C Offline
                    C Offline
                    Cobra91151
                    wrote on 26 Aug 2023, 14:28 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

                    J 1 Reply Last reply 26 Aug 2023, 14:57
                    0
                    • C Cobra91151 has marked this topic as solved on 26 Aug 2023, 14:38
                    • C Cobra91151
                      26 Aug 2023, 14:28

                      @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

                      J Offline
                      J Offline
                      JonB
                      wrote on 26 Aug 2023, 14:57 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

                      18/18

                      26 Aug 2023, 14:57

                      • Login

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