Hi,

When I do the first drop inside the QGraphicsView everything occurs correctly, but if I tried do another drop is not more accepted. Why this happens?

I think that the problem is in the "scene" but I don't know the concept behind this.

Thanks a lot.

See the code:

Qt Code:
  1. GraphicsView::GraphicsView( QWidget * parent )
  2. : QGraphicsView(parent)
  3. {
  4. setAcceptDrops(true);
  5. scene = new GraphicsScene;
  6. }
  7.  
  8. GraphicsView::~GraphicsView()
  9. {
  10. delete scene;
  11. }
  12.  
  13. void GraphicsView::dragEnterEvent(QDragEnterEvent *event)
  14. {
  15. event->accept();
  16. }
  17.  
  18. void GraphicsView::dropEvent(QDropEvent *event)
  19. {
  20. if (event->mimeData()->hasFormat("plain/text")) {
  21.  
  22. QByteArray pieceData = event->mimeData()->data("plain/text");
  23. QDataStream dataStream(&pieceData, QIODevice::ReadOnly);
  24. QString string;
  25. dataStream >> string;
  26.  
  27. qDebug() << "drop" << string;
  28.  
  29. setScene(scene);
  30. QFont sansFont("Helvetica [Cronyx]", 12);
  31. scene->addSimpleText(string,sansFont);
  32.  
  33.  
  34. event->setDropAction(Qt::MoveAction);
  35. event->accept();
  36. } else {
  37.  
  38. event->ignore();
  39. }
  40. }
To copy to clipboard, switch view to plain text mode