PDA

View Full Version : how to get both qgraphicsscene and qgraphicsitem to both accept drops



kghose
25th December 2008, 01:59
Hi Gang,

I have some items on a qgraphicsscene and I want to be able to drag and drop an item onto another or onto a blank part of the scene. Depending on whether the drop occurs over another item or over a blank part of the scene two different things happen.

The way I'm doing this currently is backwards (I think) but is the only way I can get it to work.


MyGraphicsScene::dropEvent(....) {
QGraphicsScene::dropEvent(...)
if(!event->isAccepted()) {
event->accept()
return
}
else
do what needs to be done if the drop is on an empty space
}




MyGraphicsItem::dropEvent(...) {
do things
event->ignore();
//This is why we did this. The event comes to us 'accept'ed. If it
//passes into this function we 'ignore' it as a signal to the parent
//(qgraphicsscene) that it should not operate on it. Otherwise
//the event comes with the accept flag and qgraphicsscene acts in it
//This is so ass-backwards. There should be
//a better way of doing this

}

wysota
31st December 2008, 16:55
You can install a sceneEventFilter onto every item and handle the drop there. Furthermore if you don't reimplement dropEvent in the item, the drop should be ignored and handled by the scene. Currently you are trying to handle the drop in the item and in the scene at the same time which makes little sense. You should choose one of the approaches - handle it here (x)or there. If you insist on such strange design then ignoring the event in the item is fine - that's what ignore is meant to be used for. Accept and ignore only marks event as consumed or not, it doesn't determine whether you actually did anything with it.