Can’t get Drag and Drop to Work:
I am playing around with a programming a little GUI Application. I am using the Visual Studio Add-In do design the UI and c++ for the programming. I just want to drop for example a picture from the desktop to the Application and receive the filename with the QUrl class, but when i try do drop it an “forbidden” Icon appears as courser and when i release the mouse button nothing happens.
I looked in many examples and it seems to me that you only have to setAcceptDrops(true) and it should at least accept the Dropping.
QT Version is 4.7
The constructor of my QMainWindow Class:
- {
- ui.setupUi(this);
- //Accept Drops
- setAcceptDrops(true);
- }
Thanks for any help ;)
4 replies
Jeah i copied the source from a example:
in the Header
- //Drag and Drop Events
Cpp:
- {
- {
- if(suffix=="PNG")
- {
- event->acceptProposedAction();
- // do something
- continue;
- }
- }
- }
- {
- {
- event->acceptProposedAction();
- return;
- }
- }
I set a breakpoint at the loop but the functions don’t get called.
But why isn’t there the symbol for dropping when i drag it over the application. Seems wired
I’ve just created an empty project (QMainWindow subclass), set setAcceptDrops(true) in the constructor and reimplemented
- {
- qDebug() << "dragEnter" << event->mimeData()->formats();
- event->acceptProposedAction();
- }
- {
- qDebug() << "drop" << event->mimeData()->formats();
- }
And as expected it prints the following when drag/dropping items from my file manager:
dragEnter (“x-special/gnome-icon-list”, “text/uri-list”, “UTF8_STRING”, “text/plain”, “COMPOUND_TEXT”, “TEXT”, “STRING”, “text/plain;charset=utf-8”)
drop (“x-special/gnome-icon-list”, “text/uri-list”, “UTF8_STRING”, “text/plain”, “COMPOUND_TEXT”, “TEXT”, “STRING”, “text/plain;charset=utf-8”)
Are you sure QDirectXWidget inherits from QWidget and your dragEnterEvent/dropEvent are in the protected section in the header and have correct signature etc?
You must log in to post a reply. Not a member yet? Register here!
