找回密码
 立即注册
收起左侧

QGraphicsItem与QGraphicsRectItem是继承的关系吗?急

2
回复
10312
查看
[复制链接]
累计签到:168 天
连续签到:1 天
来源: 2013-9-25 10:35:16 显示全部楼层 |阅读模式
1Qter豆
  1. #ifndef SHAPE_H
  2. #define SHAPE_H
  3. #include <QtGui>
  4. #include <QGraphicsSceneMouseEvent>
  5. #include <QGraphicsItem>
  6. #include <QObject>
  7. class Shape{//Q_OBJECT
  8. public:
  9.     enum Code { Line, Rect, Ellipse};
  10.     Shape();
  11.     virtual void startDraw(QGraphicsSceneMouseEvent *event) = 0;
  12.     virtual void drawing(QGraphicsSceneMouseEvent *event) = 0;
  13.     virtual QPointF reTurnStartPoint() = 0;
  14.     virtual QPointF reTurnEndPoint() = 0;
  15.     virtual int reTurenShape() = 0 ;
  16.     virtual void storeStartPoint(int p1,int p2) = 0;
  17.     virtual void storeEndPoint(int p1,int p2) = 0;
  18.     virtual void reDrawing() = 0;
  19.     virtual void setZvalue(int m_Zvalue) = 0;
  20. };
  21. #endif // SHAPE_H
复制代码
  1. #define RECT_H
  2. #include <QGraphicsRectItem>
  3. #include "shape.h"
  4. #include <QDebug>
  5. #include <QCursor>
  6. #include <QKeyEvent>
  7. #include <QGraphicsSceneHoverEvent>
  8. #include <QGraphicsSceneContextMenuEvent>
  9. #include <QMenu>
  10. #include <QMouseEvent>
  11. #include <QWheelEvent>
  12. #include <QGraphicsEffect>
  13. class Rect : public Shape,public QGraphicsRectItem   {
  14. public:    Rect();   // Rect();   
  15.     void startDraw(QGraphicsSceneMouseEvent *event);   
  16.     void drawing(QGraphicsSceneMouseEvent *event);   
  17.     QPointF reTurnStartPoint();   
  18.     QPointF reTurnEndPoint();   
  19.     int reTurenShape();   
  20.     void storeStartPoint(int p1,int p2);   
  21.     void storeEndPoint(int p1,int p2);   
  22.     void reDrawing();   
  23.     void setZvalue(int m_Zvalue);   
  24.     void setItemBrush();
  25.    
  26.    
  27.     void mousePressEvent(QGraphicsSceneMouseEvent *event);   
  28.     void keyPressEvent(QKeyEvent *event);   
  29.     void hoverEnterEvent(QGraphicsSceneHoverEvent *event);   
  30.     void wheelEvent(QGraphicsSceneWheelEvent *event);   
  31.     void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
  32.    
  33.     void redrawing();   
  34.     int m_Z ;   
  35.     int m_Shape;
  36.    
  37. private:    QPointF m_storeStartPoint,m_storeEndPoint;
  38. };
  39. #endif // RECT_H
复制代码
这是建立矩形类,继承QGraphicsRectItem,我想知道声明一个shape 指针,能否用这个指针去指向Rect对像








最佳答案

查看完整内容

QGraphicsRectItem继承自QAbstractGraphicsShapeItem,而QAbstractGraphicsShapeItem继承自QGraphicsItem。 关于图形视图部分的编程,建议先看下: http://www.qter.org/forum.php?mod=viewthread&tid=125 然后看下《Qt及Qt Quick开发实战讲解》上的第二个方块游戏例子。
回复

使用道具 举报

累计签到:1632 天
连续签到:2 天
2013-9-25 10:35:17 显示全部楼层
QGraphicsRectItem继承自QAbstractGraphicsShapeItem,而QAbstractGraphicsShapeItem继承自QGraphicsItem。

关于图形视图部分的编程,建议先看下:

http://www.qter.org/forum.php?mod=viewthread&tid=125

然后看下《Qt及Qt Quick开发实战讲解》上的第二个方块游戏例子。
回复

使用道具 举报

累计签到:168 天
连续签到:1 天
2013-9-27 10:39:02 显示全部楼层
yafeilinux 发表于 2013-9-25 16:26
QGraphicsRectItem继承自QAbstractGraphicsShapeItem,而QAbstractGraphicsShapeItem继承自QGraphicsItem。 ...

thanks,我这有您写的两本书,有那个方块的例子,我先去看看
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

公告
可以关注我们的微信公众号yafeilinux_friends获取最新动态,或者加入QQ会员群进行交流:190741849、186601429(已满) 我知道了