[Solved] Drag&Drop without QDrag



  • I will be trying to replace a drag&drop-enabled widget that was based around QDrag with "something else", since QDrag is limiting me too much. I want to be able to drag around widgets (like QLabels) between different "container" widgets. Even QML might be a possibility, but it would have to be integrated with an existing C++ application.

    Right now I am trying to make out problems and come up with a nice idea to implement drag&drop into my application - I would be happy about any kind of input/ideas etc. :)


  • Lifetime Qt Champion

    Hi,

    Can you give an example of what a drag and drop operation would perform ?



  • I am bundling up some data (could be a couple of megabytes) that is encapsulated by a custom QLabel. The mouse-cursor should be sensitive to where the mouse is currently pointing (if it hits a draggable object, it should change shape). I think that part is already done.

    The label should be movable between a number of widgets of equal type (some kind of container). While a label is being dragged on top of a container, the container should change color (or somehow give away that it would accept the drop).

    After the dragging is done, I want to be able to read out which label has been positioned on which container. And I need some methods to automatically move the labels around, too.

    Right now I am wondering if I should make the label a child of whatever container it is currently belonging to or if the frequent changes of parents will cause problems.



  • I finished my Drag&Drop-alternative by now. The code is about 33% shorter than the initial QDrag-code I used (I had a QDrag implementation working but felt limited by it) and it is pretty easy to add graphical features now since I am moving around actual widgets - I don't even have to block the eventloop. The only drawback is that I am unable to drag around objects between applications now - not a feature I need, but it would certainly be a lot more difficult (if not impossible) than when using QDrag (which drags around actual data represented by a pixmap, not a QObject like I do now).

    Thread is declared "solved" then.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.