[Qt-interest] Scrolling Contents in QScrollArea

Bo Thorsen bo at fioniasoftware.dk
Wed Feb 2 09:00:03 CET 2011


Den 02-02-2011 08:01, Sujan Dasmahapatra skrev:
>
> Dear Friends
>
> I am using a QScrollArea which I can see some contents  in it. By 
>  using the following  code snippet I am able to see both the vertical 
> and horizontal scrollbar. I am also implementing the virtual function
>
> //////////////////////////////////////////////////////////////////////////////////////////////////////////
>
> #include <QScrollArea>
>
> Class PageForGraph : public QScrollArea
>
> {
>
>    Q_OBJECT
>
> Public:
>
> PageForGraph(QWidget  *parent=0);
>
>                 virtual ~PageForGraph();
>
> };
>
> PageForGraph::PageForGraph(QWidget *parent)
>
> {
>
>                 verticalScrollBar()->setRange(0, 2 * desk->height());
>
>                 horizontalScrollBar()->setRange(0, 2 * desk->width());
>
> }
>
> void PageForGraph::scrollContentsBy(int dx, int dy)
>
> {
>
>                 widget()->move(widget()->x() + dx, widget()->y() + dy);
>
>                 const int x = horizontalScrollBar()->value() + dx;
>
>                 horizontalScrollBar()->setValue( x );
>
>                 const int y = verticalScrollBar()->value() + dy;
>
>                 verticalScrollBar()->setValue( y );
>
>                 update();
>
> }
>
> But when I moving the scrollbar  my contents are not moving. Any help 
> would be highly appreciated. Thanks sujan
>

You are moving in the wrong direction here. Implement your graph widget 
to show off the graph and add it to a QScrollArea. And remember to set 
the size of the widget.

If you want to implement a widget that has it's own scrollbars, then 
subclass QWidget, add two scrollbars yourself, and paint the widget 
according to the scrollbar positions.

And please read the documentation for the class: 
http://doc.qt.nokia.com/4.7/qscrollarea.html.

Bo Thorsen,
Fionia Software.

-- 

Expert Qt and C++ developer for hire
Contact me if you need expert Qt help
http://www.fioniasoftware.dk

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


More information about the Qt-interest-old mailing list