PDA

View Full Version : QGraphicsScene doesn't accept Drops



momesana
11th July 2007, 22:32
Hi,
I have a Class derived from QGraphicsScene. I've reimplemented its dragEnterEvent() and dropEvent() event handler. in dragEnterEvent I test for a custom mimetype and in a case of success call AcceptProposedAction(true). So far it works, but drops are still not supported. AcceptProposedAction() seems to have no effect. The cursor icon also indicated that drops are still not accepted by the QGraphicsScene. I guess the problem is that I want the Scene itself to handle the drops instead of any items on the scene. But that is exactly what I want.

can anybody help me with this?

thanks in advance
momesana

jpn
12th July 2007, 10:34
Perhaps you have to reimplement dragMoveEvent() and accept the event there also.

rajesh
12th July 2007, 11:13
Momesana,
Do you want to drag and drop in same widget(QGraphicsScene) or from different widget?
what type of item you moving?

fullmetalcoder
12th July 2007, 13:32
Did you enable drops in the QGraphicsView (have alook at the Drag Mode property (http://doc.trolltech.com/4.3/qgraphicsview.html#dragMode-prop)...) ?

momesana
12th July 2007, 20:15
Thank you all for replying to my post.
The reimplementation of dragMoveEvent did the trick :).
I was really frustated yesterday after I couldn't get it to work after 5 hours of trial and error experiments. Today I was demoralized enough to give up and try another approach. I made the QGraphicsView catch the Event.

This also failed so I looked up the Qt Drag and Drop online documentation and searched for examples and noticed that in the examples dragMoveEvent is also implemented. I did the same and QGraphicsView could successfully catch the events. But it didn't come to my mind to apply this knowledge to GraphiscScene. I just tried it now after reading your replies and it works. Thanks jpn :)

Bitto
15th July 2007, 10:43
It's because QGraphicsScene provides a default implementation of dragMoveEvent that checks if there are items on the scene under the cursor that accept drop events. If not, the event will be ignored, and you won't be allowed to drop.