QGraphicsItem move event - get absolute position

一世执手 提交于 2019-12-05 09:42:10

It's not a bug, it is standard behavior.

The constructor asks for a QRectF to determine the ellipse its size and its origin. Two commonly used sizes are (0,0,width,height) (origin at topleft) and (-0.5 * width, -0.5 * height, width, height) (origin at center).

With setPos, that origin is set at the desired position.

I found the reason: the constructor QGraphicsEllipseItem::QGraphicsEllipseItem ( qreal x, qreal y, qreal width, qreal height, QGraphicsItem * parent = 0 ) does not work as expected. after calling it with some x and y the item still reports 0,0 as its position. giving 0,0 to constructor and explicitly setting position with setPos(x,y) solves the thing.

I really wonder that was the intention for this behaviour. The documentation gives no hint for this.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!