[Qt-interest] how to restore a saved scoll position

Zoltan Molnar zoltan.molnar at lmsintl.com
Thu Feb 11 09:12:55 CET 2010


The solution I found is to use the centerOn logic of the view:

 

// upon save:

QGraphicsView* v = scene->views().front();

QPointF cnt = v->mapToScene(QPoint( v->viewport()->width()/2,
v->viewport()->height()/2));

outstream << cnt.x() << cnt.y();

 

 

// upon load, simply recenter using the loaded aHor, aVer values

QGraphicsView* v = mGraphicsScene->views().front();

Instream >> aHor; Instream >> aVer;

v->centerOn(aHor, aVer);

 

 

The problem with the 

 

v->horizontalScrollBar()->setSliderPosition(vvv); 

 

approach was that it didn't work properly when there was __no__
transformation matrix applied (zoom). 

 

 

Thanks for the suggestions, anyway.

Zoli

 

 

-----Original Message-----

From: qt-interest-bounces at trolltech.com [mailto:qt-interest- 

 

> v->horizontalScrollBar()->setSliderPosition(vvv);

 

Why, what is wrong with this?

 

Unless your model changes at some time and the position is invalid.

 

If this is the case you can try to ensure a certain item is visible.

Don't know any functions from the top of my head, but I guess that the
view has some way to achieve that...

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100211/e62daf81/attachment.html 


More information about the Qt-interest-old mailing list