PDA

View Full Version : Reject drop action for child QGraphicsItem



veiovis
13th August 2014, 13:50
Hello,

I searched for this, but somehow I can't find anything that solves this problem (I cannot believe that I am the only person with that problem).

Nevertheless, my problem is:
I have a GraphicsScene with a Tree of the same items.
On some item I want to reject the dragNdrop actions and accept the action on other items.
I Would like that the cursor shows, that the action will be rejected but it stays the same icon if I use setDropAction(Qt::IgnoreAction).

The two function implementations look like this:


void StateItem::dragEnterEvent(QGraphicsSceneDragDropEv ent *event)
{
const StateMimeData *data = qobject_cast<const StateMimeData*>(event->mimeData());
if(data && state && state->getStateClass() && data->getState())
{
event->setDropAction(Qt::LinkAction);
event->acceptProposedAction();
}
else
{
event->setDropAction(Qt::IgnoreAction);
event->acceptProposedAction();
}
}

void StateItem::dragMoveEvent(QGraphicsSceneDragDropEve nt *event)
{
dragEnterEvent(event);
}



void StateItem::dropEvent(QGraphicsSceneDragDropEvent *event)
{
const StateMimeData *data = qobject_cast<const StateMimeData*>(event->mimeData());
if(data && state && state->getStateClass() && data->getState())
{
int i = 2;
const QString newStateNameBase = data->getState()->getStateName();
QString newStateName = newStateNameBase;
while(!state->getStateClass()->addSubstate(data->getState(),newStateName, event->pos()))
{
newStateName = newStateNameBase + "_" + QString::number(i);
i++;
}
event->setDropAction(Qt::LinkAction);
event->acceptProposedAction();
}
else
{
event->setDropAction(Qt::IgnoreAction);
event->acceptProposedAction();
}
}



If I use event->ignore(); it will just be passed to the parent item.

So how do I reject the action properly, that the mouse cursor shows that it will be rejected?