开发者

QGraphicsView scroll problem

I have the following situation here: I do some drawing on a graphics scene, in one type of central widget, and some times this also involves scrolling the scene. Then the user clicks somewhere else in the application, the central widget is changed to something else (and the graphic views' scroll bar positions are saved somewhere). Now, the user wants to click back to the graphics scene, I redraw the scene (by recreating the entire graphics view window, because when the user was outside of the graphics scene he changed some values that must be changed in the graphics view too), and when I want to set the previous scrolling positions, I call the following method:

void GraphicsForm::scrollTo(int hor, int ver)
{
    m_qgv->horizontalScrollBar()->setValue(hor);
    m_qgv->verticalScrollBar()->setSliderPosition(ver);
}

and this is supposed to reposition the scroll bar to the previous values (hor, ver) saved before I changed the view (m_qgv is a QGraphicsView object).

The issue is, the neither the horizontal, nor the vertical values are being reverted correctly (they are saved correctly using the开发者_StackOverflow中文版 horizontal/verticalScrollBar()->sliderPosition() before hiding the scene), so the scroll bars do not move as much as they were before the window change, they move much more less...

Any ideas, suggestions how can I revert to the previous scroll coordinates?


If the scene rect changes after user edit, the saved scroll position will no longer be valid since the new min/max are now different.

Recentering the scene may be a better solution:

QPointF center = my_qgv->viewPort().rect().center();
center = my_qgv->mapToScene(center);
...
// user edit; reconstruct scene
//
my_qgv->centerOn(center);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜