This question is related to: Forcing QGraphicsItem to post
I want to have QGraphicsItem in a fixed place when moving around the scene.
The proposed solution is to override the void paintEvent(QPaintEvent*) subclass of QGraphicsView .
void MyGraphicsView::paintEvent(QPaintEvent*) { QPointF scenePos = mapToScene(0,0);
However, the problem is that I want everything else in the scene to remain intact, i.e. if I zoom in or move, I want all the other QGraphicsItems behave like the default.
One of the weak ways to solve this problem is to call void QGraphicsView::paintEvent(QPaintEvent*) from void MyGraphicsView::paintEvent(QPaintEvent*) .
void MyGraphicsView::paintEvent(QPaintEvent* event) { QGraphicsView::paintEvent(event); QPointF scenePos = mapToScene(0,0);
However, this adds flicker to my_item , as it was positioned first using QGraphicsView::paintEvent(event); and then using the added code
QPointF scenePos = mapToScene(0,0);
The question is, should I void MyGraphicsView::paintEvent(QPaintEvent*) from scratch and write the code for both the desired myItem behavior and the default for all other QGraphicsItems , or is there an easier way to do this?
Thanks.
c ++ qt qgraphicsscene qgraphicsview qgraphicsitem
Man of one way
source share