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(QGraphicsSceneDragDropEvent *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(QGraphicsSceneDragDropEvent *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();
}
}
void StateItem::dragEnterEvent(QGraphicsSceneDragDropEvent *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(QGraphicsSceneDragDropEvent *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();
}
}
To copy to clipboard, switch view to plain text mode
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?
Bookmarks