PDA

View Full Version : QGraphicsScene and dropEvent



prof.ebral
4th March 2010, 06:51
I want my GraphicsScene to receive drop events, but it does not seem to work. I can set an item inside my scene to receive drops, but not the scene itself.

What am I failing to read?

wysota
4th March 2010, 09:27
Did you reimplement dragEnterEvent() and/or dragMoveEvent() for the scene?

prof.ebral
4th March 2010, 11:00
I did dragEnterEvent, but then all I get is a reaction when I drag into the scene and nothing when I drop into the scene. I have not tried dragMoveEvent. I have tried dropEvent and that is not working for the scene.

wysota
4th March 2010, 11:50
dragEnterEvent() itself is not enough as the default dragMoveEvent() will ignore drags for areas not occupied by items.

prof.ebral
4th March 2010, 15:17
I tried that after I read your post, Wysota. I apologize, I should have updated my status on the thread.

After I reclass both of those, is there a third step that I am missing?

wysota
4th March 2010, 15:56
After I reclass both of those

Would you care to explain what you mean by that?

prof.ebral
4th March 2010, 17:17
Sorry. I meant re-implement. In PyQt I just add the function to the class when the event occurs the function is called.

wysota
4th March 2010, 20:24
And what did you put in those reimplementations?

prof.ebral
5th March 2010, 01:13
just print statements so I could determine if they are working.

wysota
5th March 2010, 10:32
That's not enough. You have to make sure those events are accepted.

prof.ebral
5th March 2010, 16:17
How do I determine that?

prof.ebral
5th March 2010, 18:01
I think I have stumbled on to part of my problem. If I reimplement dropEvent in the GraphicsView, that reimplementation takes precedence over my Scene, and any items in that Scene. If I reimplement dropEvent in my Scene, that takes precedence over any items in the scene.

What I need is a decision making process so the dropEvents can be sent to the correct reimplementation.

prof.ebral
5th March 2010, 20:03
ok .. I looked over the Graphics View Framework again and this is the way I understand it. GraphicsView events are called first and are then forwarded to the scene. Scene events events then forward the event to the Item.

Because of this framework it sounds impossible to actually drag and drop an item onto a Scene or a View, I would need to have an Item to accept that dropEvent. Is that correct? Is there any way to work around this so I can drop directly onto the Scene or the View?

prof.ebral
5th March 2010, 23:46
Oddly Wysota, when I tried what you had recommended it did not work as I thought it would. I reorganized my script so that it is cleaner and tried again. Thanks!

wysota
6th March 2010, 09:16
[QUOTE=prof.ebral;135171Because of this framework it sounds impossible to actually drag and drop an item onto a Scene or a View, I would need to have an Item to accept that dropEvent. Is that correct? Is there any way to work around this so I can drop directly onto the Scene or the View?[/QUOTE]

You can always call the base class implementation of the event to "forward" the drop from the view to the scene and then to the item.