Reputation: 2581
I have a QMainWindow with two QGraphicsView's each owning a QGraphicsScene. Both views are displayed (on screen) constantly. I would like to be able to drag and drop objects (objects of a class subclassed from QGraphicsItem) from one QGraphicsView to the other. What's the best way to do this?
ps: I can drag and drop inside one QGraphicsView
Upvotes: 2
Views: 641
Reputation: 12317
In the views mouse event create a new drag object to contain the data you want moved, for example:
QDrag* drag = new QDrag( this );
QByteArray ba;
QDataStream* data = new QDataStream(&ba, QIODevice::WriteOnly);
*data << m_slideIndex;
QMimeData* myMimeData = new QMimeData;
myMimeData->setData("application/x-thumbnaildatastream", ba);
drag->setMimeData( myMimeData );
drag->setPixmap( thumb );
drag->setHotSpot( thumb.rect().center() );
if ( drag->exec() == Qt::IgnoreAction )
{
qDebug() << "DRAG CANCELLED";
m_dragging = false;
}
drag->deleteLater();
delete data;
And then in the QGraphicsScene's dropEvent() implement the catch for that data.
Upvotes: 2