Results 1 to 4 of 4

Thread: QBoxLayout removeWidget problem

  1. #1
    Join Date
    Aug 2006
    Posts
    5
    Thanks
    1

    Default QBoxLayout removeWidget problem

    I have a QBoxLayout and I want to delete some widget from it. That widget was created like this:

    QWidget qw;

    QComboBox combo=new QComboBox(&qw); //parent the principal widget
    QComboBox combo2=new QComboBox(&qw);
    ...

    center_layout->addWidget(&qw);

    With the last instruction the widget appears perfectly in the window, but when I try to remove it with
    center_layout->removeWidget(&qw);
    it doesn't work. The widget still appears in the window and I can interact with it.
    So.. how can I remove this widget completly?

    Jaime

  2. #2
    Join Date
    Aug 2006
    Posts
    5
    Thanks
    1

    Default Re: QBoxLayout removeWidget problem

    Finally I solved this doing a setParent(0); that way it is not painted anymore.

  3. #3
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QBoxLayout removeWidget problem

    You should have called hide() on the widget. setParent(0) will just make the widget into a toplevel widget (no parent). Look around carefully and no doubt it is floating around on your desktop somewhere (or it will after a show()).
    Save yourself some pain. Learn C++ before learning Qt.

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QBoxLayout removeWidget problem

    QLayout::removeWidget() does only remove the widget from the layout so that it's geometry won't be anymore managed by the layout. The widget will be left there where it was during the removal. If you want to get completely rid of the widget, delete it. If you will need it later, hide it. Just be aware that reparenting it with no parent makes it just a top level widget as CBM already stated. That's most probably not what you want.
    J-P Nurmi

Similar Threads

  1. QTimer problem ... it runs but never triggs
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 4th July 2006, 12:54
  2. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45
  3. Problem with bitBlt
    By yellowmat in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 14:08
  4. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.