Results 1 to 2 of 2

Thread: how to modify contents of QScrollArea?

  1. #1
    Join Date
    Dec 2009
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default how to modify contents of QScrollArea?

    Hi,
    I'd like to make a 'quiz' and I assumed I should add the long list of questions and radiobutton answers into a QScrollArea so they could all be seeen by the user. I'm having trouble to populate the scrollarea procedurally. In the Designer, I've been able to add mock-up questions to the scrollarea, but I can't even remove these mock-ups using my C++ code. I assume that if I can delete these children, I will know how to add content too.

    I tried iterating over the "children of the scrollbar's widget's layout" (it hurts a little to say that). Here is my code to do that, which has a bad side-effect; the children render in a different place instead of just being deleted. I'd like to know the right way to delete the content of a scrollarea, thanks for any tips!

    Qt Code:
    1. QWidget* scrollarea_content = ui->_quiz_scrollarea->widget();
    2. if( scrollarea_content )
    3. {
    4. //what is this? scrollarea_content->children();
    5.  
    6. QLayout* scrollarea_layout = scrollarea_content->layout();
    7.  
    8. if( scrollarea_layout )
    9. {
    10. QLayoutItem *child;
    11. while ((child = scrollarea_layout->takeAt(0)) != 0)
    12. {
    13. delete child;
    14. }
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Apr 2009
    Location
    Italy
    Posts
    70
    Thanks
    23
    Thanked 15 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to modify contents of QScrollArea?

    I believe the problem is that you are not resetting the widget parent (i.e. you are removing it from the layout, but it is still a child of the scroll area)

    Try something like this:

    Qt Code:
    1. QLayoutItem *child;
    2.  
    3. while ((child = scrollarea_layout->takeAt(0)) != 0)
    4. {
    5. child->widget()->setParent(0);
    6. delete child;
    7. }
    To copy to clipboard, switch view to plain text mode 
    (I am sorry I cannot test the code at the moment)

Similar Threads

  1. How to modify QHash values?
    By darshan in forum Qt Programming
    Replies: 1
    Last Post: 19th February 2009, 12:47
  2. Modify a ContextMenu
    By smarinr in forum Qt Programming
    Replies: 5
    Last Post: 10th May 2008, 17:41
  3. Replies: 2
    Last Post: 10th March 2008, 20:16
  4. I have a problem to modify table
    By Abk in forum Qt Programming
    Replies: 1
    Last Post: 31st May 2007, 20:11
  5. Modify model data in QTreeView
    By YuriyRusinov in forum Qt Programming
    Replies: 6
    Last Post: 26th October 2006, 17:28

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.