I created simple d&d drop - soemthing like QT Creator menu - ListView on the side and DragScene (my own subclass of QGraphicsScene). I want to created new Graphic item ( i already got my custo mclasses for it) to be added there - in place where i dropped it. I created my own class:
DragScene.h
#include <QGraphicsScene>
#include <QDebug>
#include <QMimeData>
#include "CustomObj.h"
class DragScene : public QGraphicsScene
{
public:
DragScene(QObject* parent = 0);
protected:
void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
void dragMoveEvent(QGraphicsSceneDragDropEvent *event);
void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
void dropEvent(QGraphicsSceneDragDropEvent *event);
};
DragScene.cpp
#include "DragScene.h"
DragScene::DragScene(QObject* parent)
: QGraphicsScene(parent)
{
}
void DragScene::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
{
}
void DragScene::dragMoveEvent(QGraphicsSceneDragDropEvent *event)
{
}
void DragScene::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
{
}
void DragScene::dropEvent(QGraphicsSceneDragDropEvent *event)
{
CustomObj* newObject = new CustomObj(0,0,50,50);
// newObject->setPos(event->pos().x(), event->pos().y()); //(1)
this->addItem(newObject);
qDebug() <<"New object";
}
Now I jsut can't set those parameters. Everytime i try to use event (like in (1) ) in those functions I get errors:
invalid use of incomplete type 'class QGraphicsSceneDragDropEvent' newObject->setPos(event->pos().x(), event->pos().y()); ^
forward declaration of 'class QGraphicsSceneDragDropEvent' class QGraphicsSceneDragDropEvent; ^
invalid use of incomplete type 'class QGraphicsSceneDragDropEvent' newObject->setPos(event->pos().x(), event->pos().y()); ^
forward declaration of 'class QGraphicsSceneDragDropEvent' class QGraphicsSceneDragDropEvent; ^
I have no idea why anymore - i saw few exemples and those wre useing event without any trouble, like: Qt - drag and drop with graphics view framework
EDIT 1: Adding:
#include <QGraphicsSceneDragDropEvent>
recolved it, but now I can see my event isnt passing any position - every object is stted to (0,0).
How about this:
#include <QGraphicsSceneDragDropEvent>