Results 1 to 14 of 14

Thread: How to reset a QGroupBox's layout?

  1. #1
    Join Date
    Jun 2009
    Location
    Zhengzhou, China
    Posts
    16
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X

    Question How to reset a QGroupBox's layout?

    Hi,

    Just like the title.

    Thanks very much!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to reset a QGroupBox's layout?

    The title doesn't really say much...
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jun 2009
    Location
    Zhengzhou, China
    Posts
    16
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: How to reset a QGroupBox's layout?

    And the previous layout should not be deleted, because it may be used again.

  4. #4
    Join Date
    Jun 2009
    Location
    Zhengzhou, China
    Posts
    16
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: How to reset a QGroupBox's layout?

    Quote Originally Posted by wysota View Post
    The title doesn't really say much...
    Sorry

    The problem is one QGroupBox is created, and set its layout to a QVBoxLayout, later the layout should be changed to another QVBoxLayout ( the content is different ), so how to change QGroupBox's layout without deleting the previous QVBoxLayout?

    Execuse my poor English.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to reset a QGroupBox's layout?

    Remove all the "old" widgets from the layout using QLayout::removeWidget() and add all the "new" ones using QLayout::addWidget(). You don't need to set a new layout, the one that's already there is ok.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Jun 2009
    Location
    Zhengzhou, China
    Posts
    16
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: How to reset a QGroupBox's layout?

    Quote Originally Posted by wysota View Post
    Remove all the "old" widgets from the layout using QLayout::removeWidget() and add all the "new" ones using QLayout::addWidget(). You don't need to set a new layout, the one that's already there is ok.
    I made a class with a layout menber, and add other widgets in the class to this layout. Because I think this may be easier to represent the content of the class in different places. So any suggesion?

    Thanks very much!

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to reset a QGroupBox's layout?

    Why (and where) do you think my previous post was not clear enough?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Jun 2009
    Location
    Zhengzhou, China
    Posts
    16
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: How to reset a QGroupBox's layout?

    Quote Originally Posted by wysota View Post
    Why (and where) do you think my previous post was not clear enough?
    Because you said all the widgets should be removed, that is not what I wish. And the class which I made contains its own layout, it can be used as layout manager by external widgets.

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to reset a QGroupBox's layout?

    Quote Originally Posted by dongli View Post
    Because you said all the widgets should be removed, that is not what I wish.
    Ok, so you want to change one vertical layout to another vertical layout and both layouts should contain the same widgets. Is that correct? If so, then what exactly do you want to change? Because for me it seems that if you have two vertical layouts showing the same widgets in the same order then those layouts are identical.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #10
    Join Date
    Jun 2009
    Location
    Zhengzhou, China
    Posts
    16
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: How to reset a QGroupBox's layout?

    Quote Originally Posted by wysota View Post
    Ok, so you want to change one vertical layout to another vertical layout and both layouts should contain the same widgets. Is that correct? If so, then what exactly do you want to change? Because for me it seems that if you have two vertical layouts showing the same widgets in the same order then those layouts are identical.
    No, the widgets are not the same! For example, there are two instances of that class, A and B. Both of them have a vertical layout, and several other widgets like spin box. They will be displayed on a group box alternatively, by changing the layout of the group box ( if that can be accomplished ).

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to reset a QGroupBox's layout?

    Quote Originally Posted by dongli View Post
    No, the widgets are not the same!
    So you do want to remove widgets from the layout. Read my post where I wrote about removing widgets from the layout.

    They will be displayed on a group box alternatively, by changing the layout of the group box ( if that can be accomplished ).
    Maybe you just want a QStackedLayout?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #12
    Join Date
    Jun 2009
    Location
    Zhengzhou, China
    Posts
    16
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: How to reset a QGroupBox's layout?

    So you do want to remove widgets from the layout. Read my post where I wrote about removing widgets from the layout.
    I use example to express my idea~

    For example, the class is declared like:
    Qt Code:
    1. class MyWidget : public QWidget
    2. {
    3. ...
    4. QVBoxLayout *layout;
    5. QLabel *label;
    6. ...
    7. };
    8. ...
    9. MyWidget::MyWidget(QWidget *parent)
    10. : QWidget(parent)
    11. {
    12. ...
    13. layout->addWidget(label);
    14. ...
    15. }
    16. ...
    To copy to clipboard, switch view to plain text mode 

    And there two instances A and B, they will be displayed on QGroupBox, say C

    First, display A on C
    Qt Code:
    1. ...
    2. C.setLayout(A.layout); // here the label of A will be displayed on C
    3. ...
    To copy to clipboard, switch view to plain text mode 

    Then I want to display B on C alternatively, my question is how, and the layout of A should not be deleted.

    Thanks for your patience!

  13. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to reset a QGroupBox's layout?

    I already answered your question.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  14. #14
    Join Date
    Jun 2010
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to reset a QGroupBox's layout?

    Qt Code:
    1. while(!hlayout->isEmpty()){
    2. hlayout->removeItem(hlayout->itemAt(0));
    3. }
    To copy to clipboard, switch view to plain text mode 

    that works for me..
    i was searching for a clear or reset function too..

Similar Threads

  1. changing layout of a widget
    By mikro in forum Qt Programming
    Replies: 10
    Last Post: 4th August 2009, 20:21
  2. Qt like Layout Manager available for .NET platform
    By vkhaitan in forum Qt Programming
    Replies: 0
    Last Post: 5th November 2008, 13:36
  3. Qt layout memory issue
    By bunjee in forum Qt Programming
    Replies: 9
    Last Post: 25th August 2007, 17:11
  4. Resizing problems when applying a layout
    By JimBrown in forum Newbie
    Replies: 1
    Last Post: 21st February 2007, 22:54
  5. "dynamic" layout
    By hulk in forum Qt Programming
    Replies: 2
    Last Post: 9th May 2006, 07:16

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.