Results 1 to 8 of 8

Thread: delete/add layout, or modify existing layout?

  1. #1
    Join Date
    Apr 2007
    Location
    Rakovnik, Czech Republic
    Posts
    175
    Thanks
    43
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default delete/add layout, or modify existing layout?

    I have a QHBoxLayout that contains QWidgets: a label and some buttons. Along the bottom of my application are 6 QPushButtons ("MainButtons"). When I hit the first MainButton, I want the QHBoxLayout to contain a label and 4 buttons. When I hit the second MainButton, I want the label and 4 buttons in the QHBoxLayout to disappear, and be replaced with a different label and different buttons that will have different properties/functions.

    How should I go about this? Should I create 6 separate QHBoxLayout objects--each containing its unique label and buttons--and hide/show them depending on which MainButton is pushed? Or should I create a single QHBoxLayout, and removeWidget/addWidget depending on which MainButton is pushed?
    Last edited by vonCZ; 13th June 2007 at 18:55.

  2. #2
    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: delete/add layout, or modify existing layout?

    I'd suggest using QStackedWidget (or QStackedLayout). It'll save you from flickering problems.
    J-P Nurmi

  3. #3
    Join Date
    Apr 2007
    Location
    Rakovnik, Czech Republic
    Posts
    175
    Thanks
    43
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: delete/add layout, or modify existing layout?

    thanks jpn. From Assistant: "QStackedLayout class provids a stack of widgets where only one widget is visible at a time." Is there a Class in which I could put a stack of Layouts? ...so that only one layout is visible at a time?

  4. #4
    Join Date
    Apr 2007
    Location
    Rakovnik, Czech Republic
    Posts
    175
    Thanks
    43
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: delete/add layout, or modify existing layout?

    Any Ideas here? I have my layouts, but I still don't know how to delete (or hide) them from the rootLayout.

    Qt Code:
    1. //creates 5 QHBoxLayouts
    2. for(int a=0; a<5; a++)
    3. {
    4. createLayouts(a);
    5. }
    6.  
    7.  
    8. rootLayout->addLayout(layout[0]); //only adds the first layout
    9.  
    10. // function() will hide/remove "layout[0]" and show/add layout[1]
    11. connect(mainButton1, SIGNAL(clicked()), this, SLOT(function()));
    To copy to clipboard, switch view to plain text mode 

    but I don't see a way to hide or remove the first layout[0]
    Last edited by vonCZ; 15th June 2007 at 15:39.

  5. #5
    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: delete/add layout, or modify existing layout?

    Install each layout on a plain QWidget and add them to a QStackedWidget.
    J-P Nurmi

  6. The following user says thank you to jpn for this useful post:

    vonCZ (15th June 2007)

  7. #6
    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: delete/add layout, or modify existing layout?

    Sorry for such a short answer, I was in hurry. Anyway, as mentioned, I'd suggest installing each layout on a plain QWidget and then adding them to a QStackedWidget. Furthermore, you may construct a QButtonGroup out of the main buttons for switching pages more or less like this:
    Qt Code:
    1. QStackedWidget* stack = new QStackedWidget(this);
    2. ...
    3. QWidget* page1 = new QWidget(stack);
    4. page1->setLayout(layout[0]);
    5. stack->addWidget(page1);
    6. ...
    7. QWidget* page2 = new QWidget(stack);
    8. page1->setLayout(layout[1]);
    9. stack->addWidget(page2);
    10. ...
    11. QButtonGroup* group = new QButtonGroup(this);
    12. group->addButton(btn1, 0); // "page1" at index 0
    13. group->addButton(btn2, 1); // "page2" at index 1
    14. ...
    15. connect(group, SIGNAL(buttonClicked(int)), stack, SLOT(setCurrentIndex(int)));
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  8. #7
    Join Date
    Apr 2007
    Location
    Rakovnik, Czech Republic
    Posts
    175
    Thanks
    43
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: delete/add layout, or modify existing layout?

    gotcha (i think): create 5 layouts with their respective widgets (buttons & labels). Also create 5 QWidgets; do:
    Qt Code:
    1. myQWidget_0->addLayout(myLayout_0);
    To copy to clipboard, switch view to plain text mode 

    for myQWidgets 0-4, then use QStackWidget to manage.

    ...working on it.

  9. #8
    Join Date
    Apr 2007
    Location
    Rakovnik, Czech Republic
    Posts
    175
    Thanks
    43
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: delete/add layout, or modify existing layout?

    just saw your second response: excellent, thanks for the advice/direction.

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.