Results 1 to 10 of 10

Thread: Remove column from QGridLayout

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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: Remove column from QGridLayout

    i use qlayout::removeitem() but it doesn't get removed.
    Oh, I see now.
    But you "are doing it without doing it".
    What I mean is, you ask the layout for the items.
    Instead, you must have the pointers to the objects somewhere right, so use these pointers in remoevItem() - don't ask the layout for them.

    To do it the way you are doing it, you need to keep track of everything you add and remove to the layout, but why would you want to do that - that is what the layout it for!
    Asking the layout for the viewer in a given cell only guarantees you that you get a pointer to a viewer (if any) which is in that cell - but if your bookkeeping is wrong, you are not getting the viewer you expect, or, not any viewer at all.
    Last edited by high_flyer; 28th June 2012 at 14:37.
    ==========================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.

  2. #2
    Join Date
    Dec 2010
    Posts
    55
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Remove column from QGridLayout

    Quote Originally Posted by high_flyer View Post
    Oh, I see now.
    To do it the way you are doing it, you need to keep track of everything you add and remove to the layout, but why would you want to do that - that is what the layout it for!
    I think I see what you mean.
    I was was not tracking the pointers after they are added to the layout.
    I was depending on the ability to find the pointer by asking the layout.

    Therefore, what would you propose is the best way I can accomplish this.

    I can try tracking all my pointers and deleting directly but as you say "thats what a layout is for"
    I can also ask the layout for the items, but that doesnt seem to be working right for me.
    Running:
    RHEL 5.4
    Python 2.7.2
    Qt 4.7.4
    SIP 4.7.8
    PyQt 4.7

  3. #3
    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: Remove column from QGridLayout

    Hmm... after thinking about it a bit more:

    I am not sure what's QLayout policy in a case when you add a viewer to an already occupied cell.
    Does it put the widgets on top of each other or creates a new row/column (cell).
    I'd expect the later which is the reason I thought working with the layout position is not reliable.
    However if the layout stacks the widgets, then your approach should work, but the question then is, which of the stacked widgets (in a cell) do you get?

    Test it.


    At any rate, you don't really need to track or manage anything, you just need to store the pointers of your widgets.
    A QVector, or a QList is ok.
    You don't need the layout position if you have the pointer.
    Unless you allocate your items as children, you need these pointers to delete them, otherwise you get a memory leak.
    ==========================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. Replies: 3
    Last Post: 9th October 2012, 02:12
  2. QSqlTableModel remove column by name
    By qlands in forum Qt Programming
    Replies: 2
    Last Post: 5th July 2011, 12:48
  3. Replies: 1
    Last Post: 7th April 2011, 21:18
  4. Limit number of row/column in QGridLayout
    By EricF in forum Qt Programming
    Replies: 2
    Last Post: 18th October 2007, 19:54
  5. Remove a QLayout from QGridLayout
    By grosem in forum Qt Programming
    Replies: 18
    Last Post: 2nd January 2007, 11:19

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.