Trying to drag & drop label from QWidget to QGraphicsScene. I have made custom implementation from QLabel. Also QGraphicsView is accepting drops. The problem is that QGraphicsScene doens't get any events when dropping element to it.
QLabel implementation .cpp
void ItemLabel::mousePressEvent(QMouseEvent *ev)
{
if(ev->button() == Qt::LeftButton){
QDrag *drag = new QDrag(this);
QMimeData *mimeData = new QMimeData;
mimeData->setText("Test");
drag->setMimeData(mimeData);
drag->setPixmap(*this->pixmap());
drag->exec();
Qt::DropAction dropAction = drag->exec(Qt::CopyAction | Qt::MoveAction);
}
}
Scene .cpp
void Scene::dropEvent(QGraphicsSceneDragDropEvent *event)
{
event->acceptProposedAction();
qDebug() << "drop";
}
void Scene::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
{
if(event->mimeData()->hasFormat("text/plain"))
event->acceptProposedAction();
}
What I need to do to get scene receive drops?