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

Jefferson Bandeira jbsilva at ufrj.br
Fri Feb 5 15:05:51 CET 2010


You could try QSettings, is quite simples and good to use, check online docs
or QAssistant

2010/2/5 Zoltan Molnar <zoltan.molnar at lmsintl.com>

>  Hi all,
>
>
>
> I would like to restore a view in the scrolled position it was before
> exiting an application.
>
> I currently use the following logic to save and load the actual scroll pos:
>
>
>
>
> Upon save I inquire the sliderPosition of both scrollbars:
>
>
>
> void save(QGraphicsView* v)
>
> {
>
>    QScrollBar *h_sb = v->horizontalScrollBar();
>
>    QScrollBar *v_sb = v->verticalScrollBar();
>
>    int aHorizVal = h_sb->sliderPosition();
>
>    int aVerticVal= v_sb->sliderPosition();
>
>    outstream << aHorizVal << aVerticVal;
>
> }
>
>
>
> Load is called after the scene has been populated already.
>
>
>
> void load(QGraphicsView* v)
>
> {
>
>    int h_val, v_val;
>
>    inpstream >> h_val; inpstream >> v_val;
>
>    QScrollBar *h_sb = v->horizontalScrollBar();
>
>    QScrollBar *v_sb = v->verticalScrollBar();
>
>    h_sb->setSliderPosition(h_val);
>
>    v_sb->setSliderPosition(v_val);
>
> }
>
>
>
> Can anybody recommend me a better way to do this? This seems to me a little
> fragile.
>
>
>
> Br, Zoltan
>
>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>


-- 
Jefferson Bandeira
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100205/19b7ce62/attachment.html 


More information about the Qt-interest-old mailing list