• 4336阅读
  • 3回复

[提问]关于QGraphicItem继承的问题 [复制链接]

上一主题 下一主题
离线bmzypeng
 

只看楼主 倒序阅读 楼主  发表于: 2016-01-19
我自定义了一个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;
};
离线weinkym

只看该作者 1楼 发表于: 2016-01-19
应该实现这两个接口就可以了 rebuild 试试
离线tylan

只看该作者 2楼 发表于: 2016-01-20
virtual QRectF boudingRect() const;  
virtual QPainterPath shape() const;  
virtual void paint(QPainter* painter,const QStyleOptionGraphicsItem* option,QWidget* widget);  
这是虚函数吧。。。。。。。。。。表明你这类是虚类。
离线bmzypeng

只看该作者 3楼 发表于: 2016-01-20
回 weinkym 的帖子
weinkym:应该实现这两个接口就可以了 rebuild 试试 (2016-01-19 21:48) 

找到问题了,我的那个boundingRect打错了,少打了个n
所以他没有找到关于boundingRect的实现
快速回复
限100 字节
 
上一个 下一个