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:
GraphicsView
::GraphicsView( QWidget * parent
){
setAcceptDrops(true);
scene = new GraphicsScene;
}
GraphicsView::~GraphicsView()
{
delete scene;
}
{
event->accept();
}
{
if (event->mimeData()->hasFormat("plain/text")) {
QByteArray pieceData
= event
->mimeData
()->data
("plain/text");
dataStream >> string;
qDebug() << "drop" << string;
setScene(scene);
QFont sansFont
("Helvetica [Cronyx]",
12);
scene->addSimpleText(string,sansFont);
event->setDropAction(Qt::MoveAction);
event->accept();
} else {
event->ignore();
}
}
GraphicsView::GraphicsView( QWidget * parent )
: QGraphicsView(parent)
{
setAcceptDrops(true);
scene = new GraphicsScene;
}
GraphicsView::~GraphicsView()
{
delete scene;
}
void GraphicsView::dragEnterEvent(QDragEnterEvent *event)
{
event->accept();
}
void GraphicsView::dropEvent(QDropEvent *event)
{
if (event->mimeData()->hasFormat("plain/text")) {
QByteArray pieceData = event->mimeData()->data("plain/text");
QDataStream dataStream(&pieceData, QIODevice::ReadOnly);
QString string;
dataStream >> string;
qDebug() << "drop" << string;
setScene(scene);
QFont sansFont("Helvetica [Cronyx]", 12);
scene->addSimpleText(string,sansFont);
event->setDropAction(Qt::MoveAction);
event->accept();
} else {
event->ignore();
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks