Results 1 to 3 of 3

Thread: Force a Scroll in a QScrollArea

  1. #1
    Join Date
    May 2008
    Location
    USA
    Posts
    22
    Thanks
    4
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Wink Force a Scroll in a QScrollArea

    Hi,

    I have a QScrollArea with some widgets inside and I would like to force it to scroll all the way to the right when I click a button after a new widget is created inside this scrollarea.

    This is what I have so far:
    The QScrollArea is called imageList:

    Qt Code:
    1. int max = imageList->horizontalScrollBar()->maximum();
    2. imageList->horizontalScrollBar()->setValue(max);
    To copy to clipboard, switch view to plain text mode 

    However it is not scrolling all the way to the right. It is scrolling to the element before the last one. Obviously this code is placed after adding the last widget to the QScrollArea.
    Am I doing something wrong?

    Thanks a lot in advance for your help.

  2. #2
    Join Date
    Jan 2006
    Posts
    132
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Force a Scroll in a QScrollArea

    I think at the time your code is executed the scroll area has not yet updated the scrollbar size. Try executing the code after all events are processed, by putting the code into a private slot and trigger it by a single shot timer:

    Qt Code:
    1. ...
    2. QTimer::singleShot(0, this, SLOT(scrollRight()));
    3. ...
    4.  
    5. void MyClass::scrollRight()
    6. {
    7. int max = imageList->horizontalScrollBar()->maximum();
    8. imageList->horizontalScrollBar()->setValue(max);
    9. }
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to seneca for this useful post:

    nmuntz (25th January 2009)

  4. #3
    Join Date
    May 2008
    Location
    USA
    Posts
    22
    Thanks
    4
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Force a Scroll in a QScrollArea

    That worked perfectly !
    Thanks a lot for your help!

Similar Threads

  1. Auto scroll down in QScrollArea
    By EricF in forum Qt Programming
    Replies: 2
    Last Post: 29th December 2008, 13:51
  2. QScrollArea
    By ToddAtWSU in forum Qt Programming
    Replies: 5
    Last Post: 13th December 2007, 18:20
  3. nmake problems while building mysql driver
    By MarkoSan in forum Installation and Deployment
    Replies: 27
    Last Post: 25th May 2007, 13:57
  4. Replies: 2
    Last Post: 8th October 2006, 21:14
  5. QT4 beginner Fatal Error
    By Remyfr in forum Installation and Deployment
    Replies: 3
    Last Post: 11th March 2006, 02:48

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.