Hi,
recently I started to write a Node Editor.
Right now I just use custom QGraphicsItems inside a standard scene.
The Body of the Nodes use ItemIsMoveable, the Pins are Child Items derived from QGraphicsItem.
The Pins.h file:
#ifndef NODEINPUTPLUG_H
#define NODEINPUTPLUG_H
#include <QGraphicsItem>
#include <QPainter>
#include <QMouseEvent>
#include <QDrag>
{
public:
nodeinputplug();
protected:
void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
void dropEvent(QGraphicsSceneDragDropEvent *event);
};
#endif // NODEINPUTPLUG_H
#ifndef NODEINPUTPLUG_H
#define NODEINPUTPLUG_H
#include <QGraphicsItem>
#include <QPainter>
#include <QMouseEvent>
#include <QDrag>
class nodeinputplug : public QGraphicsItem
{
public:
nodeinputplug();
QRectF boundingRect() const;
void paint(QPainter *painter,const QStyleOptionGraphicsItem *option, QWidget *widget);
QDrag *drag;
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
void dropEvent(QGraphicsSceneDragDropEvent *event);
};
#endif // NODEINPUTPLUG_H
To copy to clipboard, switch view to plain text mode
To check if the MouseEvents work i just put a qDebug() << event; in every of the Mouse handling functions.
Everything works well except dragLeaveEvent.
I tried to invoke draging like in the Drag and Drop Robot example. However if I try to create a drag object
inside the mouseMoveEvent function I just get this Error Message:
no matching function for call to 'QDrag::QDrag(nodeinputplug* const)'
no matching function for call to 'QDrag::QDrag(nodeinputplug* const)'
QDrag *drag = new QDrag(this);
To copy to clipboard, switch view to plain text mode
I also tried to create a drag object inside the constructor, but this gives me roughly the same error.
Do I have to derive from QObject also?
Bookmarks