Results 1 to 3 of 3

Thread: How delete contents in QGridLayout?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2010
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question How delete contents in QGridLayout?

    Hi, I am a new user of the forum and a beginner programmer in Qt.
    I have 2 problems.
    First:
    I have a QGridLayout in which I insert my custom widget. When I add a new widget to the list I must refresh it. So how can I delete all widget conteined in QGridLayout?

    I have tried with the following code:

    Qt Code:
    1. while(grid->layout()->count() > 0) {
    2. grid->layout()->removeWidget(grid->layout()->itemId(0)->widget());
    3. }
    To copy to clipboard, switch view to plain text mode 

    but really the widgets aren't removed. How can I solve?

    Second:
    I must do a grid in n rows x m cols in which cells I must add my custom widget. I have to add them from top-left, filling before the entire first row, then the second and so on...how can I do?
    Now I have done as before, but the widgets are placed in column.


    Thanks a lot

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: How delete contents in QGridLayout?

    Layouts do not contain widgets.
    They contain layout items.

    So, if you want to delete the widgets, first browse through the list of items, delete the widget or child layout in the item, then remove the item itself.

    In pseudo code:
    Qt Code:
    1. while layout has items
    2. layoutitem i = layout.takeat(0) //takes the first item
    3. if (i.widget())
    4. delete i.widget();
    5. if (i.layout())
    6. delete i.layout();
    7.  
    8. delete i;
    9. loop
    To copy to clipboard, switch view to plain text mode 
    Last edited by tbscope; 1st August 2010 at 14:32.

  3. #3
    Join Date
    Aug 2010
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How delete contents in QGridLayout?

    Thanks...I have solved my first problem...

    now I have this dialog:

    how can I know in partend widget which of children widget I have selected with radio button? I must know item id to modify information.

    however thank you!

Similar Threads

  1. Replies: 4
    Last Post: 19th February 2009, 11:10
  2. QGridLayOut
    By Rakesh_Kumar in forum Qt Programming
    Replies: 2
    Last Post: 9th January 2009, 04:49
  3. Delete a QGridLayout and New QGridLayout at runtime
    By sabeesh in forum Qt Programming
    Replies: 1
    Last Post: 5th November 2007, 13:01
  4. Qt 3.3 QGridLayout
    By ToddAtWSU in forum Qt Programming
    Replies: 2
    Last Post: 23rd February 2007, 17:40
  5. QGridLayout
    By ToddAtWSU in forum Qt Programming
    Replies: 5
    Last Post: 29th June 2006, 20:34

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.