我自定义了一个Item类继承自QGraphicItem类,并且重写了boundingRect() 、shape() 、paint()函数,但是我实例化这个类的时候,
使用语句 Node* node = new Node; 这样实例化的时候,还是提醒我Node类是一个抽象类,没法实例化。
这是为什么啊?
求大神讲解!!!
下面是我类的声明
class Node : public QGraphicsItem{
Q_DECLARE_TR_FUNCTIONS(Node)
public:
Node();
~Node();
void setText(const QString& text);
QString text() const;
void setTextColor(const QColor& color);
QColor textColor() const;
void setOutlineColor(const QColor& color);
QColor outlineColor()const;
void setBackgroundColor(const QColor& color);
QColor backgroundColor() const;
void addLink(Link* link);
void removeLink(Link* link);
//relize repaint the shape
virtual QRectF boudingRect() const;
//to determine the position of cursor
virtual QPainterPath shape() const;
virtual void paint(QPainter* painter,const QStyleOptionGraphicsItem* option,QWidget* widget);
void setZValue(int z);
protected:
//to change the text void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event);
//When you move the mouse, mouseMoveEvent() won't call
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
private:
QRectF outlineRect() const;
int roundness(double size) const;
QSet<Link* >myLinks;
QString myText;
QColor myTextColor;
QColor myBackGroundColor;
QColor myOutlineColor;
};