Results 1 to 2 of 2

Thread: QScrollArea and scroll

  1. #1
    Join Date
    Jul 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QScrollArea and scroll

    I apologize for my English, since this first message in English.

    There's a certain analog of the playlist in a videowidget.
    Qt Code:
    1. scrollArea = new QScrollArea();
    2. scrollAreaWidgetContents = new QWidget();
    3. scrollArea->setWidget(scrollAreaWidgetContents);
    To copy to clipboard, switch view to plain text mode 

    After that I add in layout of scrollAreaWidgetContents (QVBoxLayout) many widgets.
    How to do so that QScrollArea it was scrolled to necessary to me widget?

    While I do so:
    Qt Code:
    1. MyWidget *selectedWidget = findWidget(id);
    2. selectedWidget->mark();
    3. _ui->scrollArea->ensureWidgetVisible(selectedWidget , 0, 0);
    To copy to clipboard, switch view to plain text mode 

    After that necessary widget became selected (after mark()), but QScrollArea to it it was not scrolled.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QScrollArea and scroll

    In your situation you should get the child widget (the one you want to scroll to) position, and then use:
    void QScrollArea::ensureVisible ( int x, int y, int xmargin = 50, int ymargin = 50 )
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Scroll Bar not appearing in QScrollArea
    By coolkaps in forum Newbie
    Replies: 1
    Last Post: 2nd May 2010, 17:12
  2. Replies: 3
    Last Post: 4th February 2009, 17:52
  3. Force a Scroll in a QScrollArea
    By nmuntz in forum Qt Programming
    Replies: 2
    Last Post: 25th January 2009, 14:49
  4. Auto scroll down in QScrollArea
    By EricF in forum Qt Programming
    Replies: 2
    Last Post: 29th December 2008, 13:51
  5. QScrollArea's Scroll Bars
    By ToddAtWSU in forum Qt Programming
    Replies: 5
    Last Post: 19th September 2006, 14: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.