Results 1 to 14 of 14

Thread: How can I always keep the scroll bar at the bottom of a QScrollArea?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2010
    Posts
    10
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How can I always keep the scroll bar at the bottom of a QScrollArea?

    I was blown away by the amount of help I got here. Thanks guys For future Googlers, here's there code I ended up using.
    Qt Code:
    1. QScrollBar* scrollbar = scrollArea->verticalScrollBar();
    2. QObject::connect(scrollbar, SIGNAL(rangeChanged(int,int)), this, SLOT(moveScrollBarToBottom(int, int)));
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void moveScrollBarToBottom(int min, int max)
    2. {
    3. Q_UNUSED(min);
    4. scrollArea->verticalScrollBar()->setValue(max);
    5. }
    To copy to clipboard, switch view to plain text mode 

    Though I used Chris's method, norobro's was equally valid.

    Thanks again guys

  2. The following user says thank you to Plixil for this useful post:

    norobro (31st July 2010)

  3. #2
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: How can I always keep the scroll bar at the bottom of a QScrollArea?

    I encountered this problem several months ago. I tried several different solutions before arriving at "maximum()+1" which IMO is a kludge. I even tried calling update() on my view to insure that scroll bar value was current. Somehow I overlooked the rangeChanged(int,int) signal.

    I think that your solution is the correct one.

  4. #3

    Default Re: How can I always keep the scroll bar at the bottom of a QScrollArea?

    Quote Originally Posted by Plixil View Post
    I was blown away by the amount of help I got here. Thanks guys For future Googlers, here's there code I ended up using.
    Qt Code:
    1. QScrollBar* scrollbar = scrollArea->verticalScrollBar();
    2. QObject::connect(scrollbar, SIGNAL(rangeChanged(int,int)), this, SLOT(moveScrollBarToBottom(int, int)));
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void moveScrollBarToBottom(int min, int max)
    2. {
    3. Q_UNUSED(min);
    4. scrollArea->verticalScrollBar()->setValue(max);
    5. }
    To copy to clipboard, switch view to plain text mode 

    Though I used Chris's method, norobro's was equally valid.

    Thanks again guys
    Thank you so much it finally worked for me

  5. #4
    Join Date
    Sep 2019
    Posts
    4
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How can I always keep the scroll bar at the bottom of a QScrollArea?

    From QT source for QAbstractItemView:
    Qt Code:
    1. void QAbstractItemView::scrollToBottom()
    2. {
    3. if (d->delayedPendingLayout) {
    4. d->executePostedLayout();
    5. updateGeometries();
    6. }
    7. verticalScrollBar()->setValue(verticalScrollBar()->maximum());
    8. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QScrollArea and scroll
    By uKCuH in forum Newbie
    Replies: 1
    Last Post: 1st July 2010, 12:22
  2. Scroll Bar not appearing in QScrollArea
    By coolkaps in forum Newbie
    Replies: 1
    Last Post: 2nd May 2010, 16:12
  3. Force a Scroll in a QScrollArea
    By nmuntz in forum Qt Programming
    Replies: 2
    Last Post: 25th January 2009, 13:49
  4. Auto scroll down in QScrollArea
    By EricF in forum Qt Programming
    Replies: 2
    Last Post: 29th December 2008, 12:51
  5. QScrollArea's Scroll Bars
    By ToddAtWSU in forum Qt Programming
    Replies: 5
    Last Post: 19th September 2006, 13:27

Tags for this Thread

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.