View Full Version : delete/add layout, or modify existing layout?
vonCZ
13th June 2007, 17:32
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?
I'd suggest using QStackedWidget (or QStackedLayout). It'll save you from flickering problems. ;)
vonCZ
13th June 2007, 18:44
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?
vonCZ
15th June 2007, 15:33
Any Ideas here? I have my layouts, but I still don't know how to delete (or hide) them from the rootLayout.
//creates 5 QHBoxLayouts
for(int a=0; a<5; a++)
{
createLayouts(a);
}
rootLayout->addLayout(layout[0]); //only adds the first layout
// function() will hide/remove "layout[0]" and show/add layout[1]
connect(mainButton1, SIGNAL(clicked()), this, SLOT(function()));
but I don't see a way to hide or remove the first layout[0]
Install each layout on a plain QWidget and add them to a QStackedWidget.
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:
QStackedWidget* stack = new QStackedWidget(this);
...
QWidget* page1 = new QWidget(stack);
page1->setLayout(layout[0]);
stack->addWidget(page1);
...
QWidget* page2 = new QWidget(stack);
page1->setLayout(layout[1]);
stack->addWidget(page2);
...
QButtonGroup* group = new QButtonGroup(this);
group->addButton(btn1, 0); // "page1" at index 0
group->addButton(btn2, 1); // "page2" at index 1
...
connect(group, SIGNAL(buttonClicked(int)), stack, SLOT(setCurrentIndex(int)));
vonCZ
15th June 2007, 16:11
gotcha (i think): create 5 layouts with their respective widgets (buttons & labels). Also create 5 QWidgets; do:
myQWidget_0->addLayout(myLayout_0);
for myQWidgets 0-4, then use QStackWidget to manage.
...working on it.
vonCZ
15th June 2007, 16:13
just saw your second response: excellent, thanks for the advice/direction.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.