PDA

View Full Version : dragEnterEvent doesn't work in QGraphicsItem, what's wrong?



Gourmet
2nd March 2015, 14:36
I have a DragDropScene : public QgraphicsScene with drag processing like this:

void DragDropScene::dragEnterEvent( QGraphicsSceneDragDropEvent *event )
{
QGraphicsScene::dragEnterEvent(event);

if( event->mimeData()->hasFormat( ITEMDRAGMIMETYPE ) )
{
event->acceptProposedAction();
return;
}
event->ignore();
}

void DragDropScene::dragMoveEvent( QGraphicsSceneDragDropEvent *event )
{
dragEnterEvent( event );
}


On this scene I have item with drag processing like this:

void ConnectableItem::dragEnterEvent(QGraphicsSceneDrag DropEvent *event)
{
qDebug() << event->pos();
event->ignore();
}

void ConnectableItem::dragMoveEvent(QGraphicsSceneDragD ropEvent *event)
{
dragEnterEvent(event);
}


In constructor of ConnectableItem I have call of

setAcceptDrops( true );

All works except drag processing in ConnectableItem. Functions do not call.

Added after 1 56 minutes:

Almost solved. Call to QGraphicsScene::dragMoveEvent(event); needed in DragDropScene::dragMoveEvent(...) with code processing event separetly from dragMoveEvent(). I receive events in ConnectableItem::dragMoveEvent(). But I cannot ignore() them. They are always accepted.