QGraphicsItem 关于boundingRect的问题

初学Qt 2013-08-28 11:11:38
比如

QRectF myItem::boundingRect()
{
return QRect(-25,-25,78,78);
}

0,0 --------------->x
|
|
|
|
|
|
Y


这是我在网上看到的例子 之前也没有坐标系转换 那-25,-25是左上角起点坐标 不是应该没有坐标吗
给个解释呗
还有 我返回的那个矩形是以后的Item只能在这个矩形内绘制东西吗
...全文
825 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Marcelxx 2014-05-06
  • 打赏
  • 举报
回复
哇,还不太晚,boundingRect(....)画的图形还不是在View上,你看看你的scene上设置的坐标就知道了,item是画在QGraphicsScene上,只要在QGraphicsScene范围内就行了。画好了过后,将QGraphicsScene上的内容映射到QGraphicsView上就行了。
Inhibitory 2013-08-28
  • 打赏
  • 举报
回复
那-25,-25是左上角起点坐标 不是应该没有坐标吗 :是的 我返回的那个矩形是以后的Item只能在这个矩形内绘制东西吗:在这个矩形内绘制的东西才会被刷新
Qt 场景、视图、项应用实例,Qt整套源码,喜欢请下载: Link: #include class Node; class Link : public QGraphicsLineItem { public: Link(Node *formN, Node *toN); ~Link(); inline Node *formNode()const { return myFormNode; } inline Node *toNode() const { return myToNode; } void setColor(const QColor &c); QColor color()const; void trackNodes(); private: Node *myFormNode; Node *myToNode; }; Node: #ifndef NODE_H #define NODE_H #include <QGraphicsItem> #include class Link; class Node : public QGraphicsItem { public: Node(); ~Node(); inline void setText(const QString &text;); inline QString text()const {return myText;} inline void setTextColor(const QColor &c) { myTextColor = c; update();} inline QColor textColor()const{return myTextColor;} inline void setBackgroundColor(const QColor &c) { myBackgroundColor = c; update();} inline QColor backgroundColor()const{return myBackgroundColor;} inline void setOutLineColor(const QColor &c) { myOutLineColor = c; update();} inline QColor outLineColor()const{return myOutLineColor;} void addLink(Link *l); void removeLink(Link *l); QRectF boundingRect()const Q_DECL_OVERRIDE; QPainterPath shape() const Q_DECL_OVERRIDE; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = Q_NULLPTR) Q_DECL_OVERRIDE; protected: void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE; QVariant itemChange(GraphicsItemChange change, const QVariant &value;) Q_DECL_OVERRIDE; private: QRectF outlineRect()const; int roundness(double size)const;//计算圆角 QSet<Link *> myLinks; QString myText; QColor myTextColor; QColor myBackgroundColor; QColor myOutLineColor; }; #endif // NODE_H View: #ifndef GRAPHICSVIEW_H #define GRAPHICSVIEW_H #include #include #include class GraphicsView : public QGraphicsView { Q_OBJECT public: explicit GraphicsView(QGraphicsScene *scene, QWidget *parent = 0); protected: void wheelEvent(QWheelEvent *e); }; #endif // GRAPHICSVIEW_H

16,203

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧