我使用以下代码在事件过滤器内的图形场景中拖放单个图像现在我试图弄清楚如何将此代码应用于一次选择的多个图像拖放
将
void MainWindow::createDrag(const QPointF &pos, QWidget *widget,
QGraphicsItem *item){
QGraphicsPixmapItem *pix =static_cast<QGraphicsPixmapItem *>(item);
QByteArray byteArray(reinterpret_cast<char*>
(&pix),sizeof(QGraphicsPixmapItem*));
QDrag *drag = new QDrag(widget);
QMimeData * mimeData = new QMimeData;
mimeData->setData("Item",byteArray);
drag->setMimeData(mimeData);
drag->setPixmap(pix->pixmap());
drag->start();
}
下拉
void MainWindow::dropEvent(QGraphicsSceneDragDropEvent *event){
QByteArray byteArray = event->mimeData()->data("Item");
QGraphicsPixmapItem * pixmap = *reinterpret_cast<QGraphicsPixmapItem**>
(byteArray.data());
QGraphicsItem *blockToBeDroped = itemAt(event->scenePos());
pixmap->setParentItem(blockToBeDroped);
}