您的位置:首页 > 其它

setSceneRect

2016-07-23 19:39 831 查看
sceneRect : QRectF

This property holds the scene rectangle; the bounding rectangle of the scene.

这个函数限定了场景边框。

The scene rectangle defines the extent of the scene. It is primarily used by QGraphicsView to
determine the view's default scrollable area, and by
QGraphicsScene to manage item indexing.

extent    长度

scrollable area 可滑动区间

index 参数

If unset, or if set to a null QRectF,
sceneRect() will return the largest bounding rect of all items on the scene since the scene was created (i.e., a rectangle that grows when items are added to or moved in the scene, but never shrinks).

setSceneRect:

QGraphicsScene::QGraphicsScene ( qreal x, qreal y, qreal width, qreal height, QObject * parent =
0 )

Constructs a QGraphicsScene object,
using the rectangle specified by (x, y), and the given width and height for its scene rectangle. The parent parameter is passed to QObject's
constructor.

例子:

<span style="font-family:KaiTi_GB2312;font-size:18px;">Mainwindow.h:
QGraphicsScene *scene;

MainWindow.cpp:
scene = new QGraphicsScene;
scene->setSceneRect(-200,-200,400,400);

</span>

QGraphicsScene::setSceneRect ( qreal x, qreal y, qreal w, qreal h );
在调用这个函数时并不是setSceneRect(0,0,width,height),而是setSceneRect(-width/2,-height/2,width,height);即在QGraphicsView的坐标系统中Scene的原点并不是顶点而是中心点,与窗口的坐标系统不一致。

可以使用setSceneRect()设置QGraphicsScene的大小。如果不设置,则默认为scene中包含所有子元素的边界区域( itemsBoundingRect()函数的返回值)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: