Results 1 to 2 of 2

Thread: QScrollArea - How To Add More Than One Widget Inside QScrollArea?

  1. #1
    Join Date
    Jun 2017
    Location
    Damascus-Syria
    Posts
    6
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Question QScrollArea - How To Add More Than One Widget Inside QScrollArea?

    Hello There...
    I Was Working Around With QScrollArea And I Tried To Add Two Widgets To It,But Each Time Only The Second One Appear.
    Can I Have A Basic Example On How To Add Two Widgets To This Scroll Area?
    Thanks In Advance...

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,165
    Thanks
    235
    Thanked 662 Times in 652 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: QScrollArea - How To Add More Than One Widget Inside QScrollArea?

    When you call QScrollArea::setWidget(), it replaces the first widget with the second one. That's why it has the prefix "set" and not "add".

    Two possible routes to a solution:

    1 - Add a QLayout-based layout to the scroll area, and then add your multiple widgets to the layout

    2 - Derive a new class from QWidget, add a layout to that, and add your widgets to that layout. Then add the derived widget to the scroll area.

    The second method is the one I would choose. It is in essence exactly the same way you would create a new dialog class, except that in this case the bsae class is QWidget, not QDialog. Once you create that new widget class, you can use Qt designer to create its UI.
    Last edited by d_stranz; 24th June 2017 at 17:12.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Ho do I Expand QGrpahicsView off screen inside a QScrollArea?
    By hybrid_snyper in forum Qt Programming
    Replies: 1
    Last Post: 5th June 2013, 22:21
  2. Replies: 0
    Last Post: 16th July 2012, 10:56
  3. QwtPlot inside QScrollArea
    By mastupristi in forum Qwt
    Replies: 3
    Last Post: 13th October 2009, 05:28
  4. resizing widget inside QScrollArea
    By mastupristi in forum Newbie
    Replies: 4
    Last Post: 16th July 2009, 20:29
  5. Replies: 2
    Last Post: 10th March 2008, 21:16

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.