0
votes

I'm working on a project were I'm using a QGraphicsScene to show some multimedia objects such as images and texts using QGraphicsItem. And I have a Widget from where I can drag and drop some files from the user computer to the Scene which triggers the creation of a new QGraphicsItem.

Ok, now here's what I'm trying to do... I'd like to make those QGraphicsItem to change their images, texts, and so on when I drop an element from my Widget. In other words, I'd like to make them behave as some sort of containers that can show the dropped element. Most of this functionality is already implemented, but I coudn't make my QGraphicsItem to accept the drop events at the same time as my QGraphicsScene. When one of them is working, the other one is not.

At the end of each "drag" event from my QGraphicsScene I've inserted this code:

void SpatialScene::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
{
    (...)
    QGraphicsScene::dragEnterEvent(event);
}

When I did that, the events where reaching my QGraphicsItem just fine, but then all of my drop events where rejected by the QGraphicsScene and I have no Ideia why. (I'm receiving a IgnoreAction in the dropEvent method).

I don't know if I've made my problem clear but... Can someone help me with this? How can I make both QGraphicsScene and its QGraphicsItem to accept the drop events?

1
Do you want to accept the same drop event in both the item and the scene? Or are you talking about 2 different drops (one to the item, another to empty space in scene)?Pavel Strakhov
@PavelStrakhov The second option (One to the item, another to empty space). If I drop the file on the scene I'd like to create a new "container" represented by my QGraphicsItem, but if I do the same drop on one of my existing items, I'd like to update it to the new file. P.S.: Thanks for answering :)Mauker

1 Answers

0
votes

I just ran in to the same problem and found a solution in an other thread.

The trick here is to ALSO accept the event in the QGraphicsScene::dragMoveEvent()!

The reason is the DEFAULT implementation which ignores drag and drop events if there is no item under the mouse!

Also refer to: http://www.qtcentre.org/threads/8022-QGraphicsScene-doesn-t-accept-Drops