Results 1 to 5 of 5

Thread: replace a widget in QVBoxLayout

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2011
    Posts
    132
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default replace a widget in QVBoxLayout

    I would love to replace a widget on button action a widget which is in the middle.

    layout = new QVBoxLayout;
    layout->addWidget(_top);
    layout->addWidget(_middle);
    layout->addWidget(_bottom);

    now I can remove a widget using

    layout->removeWidget(_middle);

    but how to add another one on that spot ??

    Thanks for help.

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: replace a widget in QVBoxLayout

    Maybe try inserting the widget at correct index with insertWidget ?

  3. #3
    Join Date
    Apr 2011
    Posts
    132
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: replace a widget in QVBoxLayout

    heh, yeah that works thanks

    but removeWidget seems to not work

    layout->removeWidget(_middle1);
    layout->insertWidget(1,_middle0);

    this looks like it inserts _middle0 next to _middle1, very weird

  4. #4
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: replace a widget in QVBoxLayout

    but removeWidget seems to not work
    Are you sure the widget you want to remove is in the layout ? What if you call hide() on this widget ?
    As for your problem, you can always add all of your widgets to a layout at once in desired order, and then call show() and hide() on correct widgets. If there are only three widgets visible, with top and bottom widget constantly occupying the same place in layout, it should work.

  5. #5
    Join Date
    Apr 2011
    Posts
    132
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: replace a widget in QVBoxLayout

    Thanks hide and show worked very well, thank you. Wonder what I am doing wrong with adding/removing widget. Hope it won't effect anything.

Similar Threads

  1. QVBoxLayout to center
    By seltra in forum Newbie
    Replies: 2
    Last Post: 7th October 2010, 18:23
  2. Replace widget on tab
    By wirasto in forum Qt Programming
    Replies: 1
    Last Post: 14th August 2010, 14:01
  3. Custom Widget inside a QVboxLayout
    By nemesis in forum Qt Programming
    Replies: 5
    Last Post: 25th June 2008, 14:55
  4. How do I replace a widget?
    By pir in forum Qt Programming
    Replies: 4
    Last Post: 24th July 2006, 16:51

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.