Results 1 to 7 of 7

Thread: Scrolling Contents in QScrollArea

  1. #1
    Join Date
    Feb 2009
    Posts
    189
    Thanks
    2

    Default Scrolling Contents in QScrollArea

    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

    Qt Code:
    1. #include <QScrollArea>
    2.  
    3. Class PageForGraph : public QScrollArea
    4. {
    5. Q_OBJECT
    6. Public:
    7. PageForGraph(QWidget *parent=0);
    8. virtual ~PageForGraph();
    9. };
    10.  
    11. PageForGraph::PageForGraph(QWidget *parent)
    12. {
    13. verticalScrollBar()->setRange(0, 2 * desk->height());
    14. horizontalScrollBar()->setRange(0, 2 * desk->width());
    15.  
    16. }
    17. void PageForGraph::scrollContentsBy(int dx, int dy)
    18. {
    19. widget()->move(widget()->x() + dx, widget()->y() + dy);
    20. const int x = horizontalScrollBar()->value() + dx;
    21. horizontalScrollBar()->setValue( x );
    22. const int y = verticalScrollBar()->value() + dy;
    23. verticalScrollBar()->setValue( y );
    24. update();
    25. }
    To copy to clipboard, switch view to plain text mode 
    But when I moving the scrollbar my contents are not moving. Any help would be highly appreciated. Thanks sujan
    Last edited by Lykurg; 2nd February 2011 at 07:17. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Scrolling Contents in QScrollArea

    So why in hell you have reimplementated scrollContentsBy()? And what is desk? Please send a complete code. Furthermore how do you setup the scroll area?

    And use [code] tags!

  3. #3
    Join Date
    Feb 2009
    Posts
    189
    Thanks
    2

    Default Re: Scrolling Contents in QScrollArea

    Hi Lykurg

    desk = new QDesktopWidget;

    desk is a QDesktopWidget.

    I think for scrolling we need to reimplement scrollContentsBy().
    I want the contents in the QScrollArea to move as you scroll. How can I achieve this.

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Scrolling Contents in QScrollArea

    Quote Originally Posted by sujan.dasmahapatra View Post
    I think for scrolling we need to reimplement scrollContentsBy().
    No you don't. And by the way, why you are subclassing QScrollArea? What are you trying to acheive?
    I want the contents in the QScrollArea to move as you scroll. How can I achieve this.
    That works yout of the box. Probably you make something wrong during setup and/or when adding the widget to the scroll area.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Scrolling Contents in QScrollArea

    Quote Originally Posted by sujan.dasmahapatra View Post
    desk = new QDesktopWidget;

    desk is a QDesktopWidget.
    By the way, this has no chance on working. You can't instantiate a new desktop
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Feb 2009
    Posts
    189
    Thanks
    2

    Default Re: Scrolling Contents in QScrollArea

    Hi
    Thanks for reply. See I have done that for example.
    I have subclassed QScrollArea for some other functionalities , such as printing etc. See the code snippet below

    Qt Code:
    1. class MyScrollArea : public QScrollArea
    2. {
    3. Q_OBJECT
    4. Public:
    5. MyScrollArea(QWidget *parent=0);
    6. ~MyScrollArea();
    7. };
    8.  
    9. MyScrollArea::MyScrollArea()
    10. {
    11. QPushButton *button1, *button2;
    12. button1 = new QPushButton(this);
    13. button2 = new QPushButton(this);
    14.  
    15. setWidget(button1);
    16. setWidget(button2);
    17. }
    To copy to clipboard, switch view to plain text mode 

    I want the buttons to one on extreme left and one on extreme right so that I need to scroll them to see.
    This much is my code...But I am not able to see the scrollbars on the scrollarea and not able to scroll even. Please tell me what Can be done on this. Thanks sujan
    Last edited by wysota; 2nd February 2011 at 11:09. Reason: missing [code] tags

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Scrolling Contents in QScrollArea

    If you set one widget on the scroll area and then you set another then the latter replaces the former. QScrollArea handles one widget. If you want more, place them all into a single widget and set that widget on the scroll area. Also pay attention to what the "widgetResizable" property does.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QScrollArea clipping contents
    By tiredtyrant in forum Qt Programming
    Replies: 0
    Last Post: 11th February 2010, 18:16
  2. how to modify contents of QScrollArea?
    By cyrfer in forum Qt Programming
    Replies: 1
    Last Post: 18th January 2010, 09:28
  3. QScrollArea scrolling down not up
    By ntp in forum Qt Programming
    Replies: 5
    Last Post: 20th August 2008, 17:23
  4. Scrolling bar problem in QScrollArea
    By YuriyRusinov in forum Qt Programming
    Replies: 1
    Last Post: 4th February 2007, 21:22
  5. Replies: 2
    Last Post: 8th October 2006, 20:14

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.