简体   繁体   中英

QGraphicsItem position after changing boundingRect

I have class derived from QGraphicsItem . It contains vector of points wich I draw in paint:

for(int i = 0; i < _vertexes.size(); i++)
{
     ...
  painter->drawEllipse(_vertexes[i], POINT_RADIUS, POINT_RADIUS);
}

when I add point in _vertexes with this code

 prepareGeometryChange();
 _vertexes.pop_back();

position of points in the view is changing, boundingRect is calculated using _vertexes

How to save points positions? I don't want all points change position after adding new one if new boundingRect is bigger. By the pos() returns always the same position (0, 0) but it could be in a different position of screen.

I don't set initial sceneRect, so it was recalculated and scrolled after each increasing scene items bounding rect. Setting scene rect by ui->graphicsView->setSceneRect(x, y, width, heigh); before adding of my items solves the problem,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM