Issue with drag and drop
-
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 andQEvent::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 officialQt
build fromMaintenance Tool
to verify how it works. -
@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? -
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? -
@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/13For 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.
-
@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?
-
@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 usingWin API
andQt
? WhyQt
just ignores it and not set the debug message: "this kind ofdrag/drop
opration is not allowed"? Thanks. -
@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.
-
@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.
-
No need to change the registry values. I have found hack with
Notepad
(admin privileges) which allows to drap/drop files directly fromWindows Explorer
to my program with admin privileges. Additionally, I can drop files from another program likeTotal Commander
(with admin privileges) or mine program with admin privileges which hasQFileSystemModel
(I called it PC Explorer).Screenshot:
-
-
@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 :)
18/18