Results 1 to 5 of 5

Thread: QScrollArea -- Scroll to widget problem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2010
    Location
    Heredia, Costa Rica
    Posts
    257
    Thanks
    24
    Thanked 17 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QScrollArea -- Scroll to widget problem --Solved

    I'm replying to my post.

    Indeed this happens because the scroll area's widget changes it geometry with every button that is added. Thus, ensureWidgetVisible cannot be called immediately because the scroll area does not know its final size yet. A way around is to subclass a QWidget and emit a signal after the widget size changes (by reimplementing the resizeEvent) + setting this widget as the scroll areas's widget. After connecting the signal, ensureWidgetVisible can properly scroll to the added widget.

  2. #2
    Join Date
    Sep 2011
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QScrollArea -- Scroll to widget problem

    Hello I had the same problem and managed to fix it quite easy: Call qApp->processEvents(); before calling the ensureWidgetVisible() method.

    The idea is that when the geometry changes, events for doing that are pushed on the event queue... So you execute the events to make the geometry changes and then you can ensure the widget is visible. Of course, these things are happening in the UI thread...

    I hope this helps someone out there. Cheers!

Similar Threads

  1. Scroll Bar not appearing in QScrollArea
    By coolkaps in forum Newbie
    Replies: 1
    Last Post: 2nd May 2010, 16:12
  2. QScrollArea inner widget problem
    By agaf in forum Qt Programming
    Replies: 3
    Last Post: 19th January 2010, 18:06
  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

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
  •  
Qt is a trademark of The Qt Company.