[Qt-interest] swap out "central" layout when button is pressed with new widgets

David Boosalis david.boosalis at gmail.com
Fri Jul 31 00:43:03 CEST 2009


Perhaps QStackedWidget may fit your need/

MyMainWindow(QWidget *parent):QMainWindow(parent)
{
  stackW = new QStackedWidget();
  A *a = new A();
  B *b  =  new B();
  stackW->insertWidget(a,0);
  stackW->insertWidget(b,1);
  stackW->setCurrentIndex(0);



}

On Thu, Jul 30, 2009 at 1:35 PM, S. Aguinaga <sa_jr at yahoo.com> wrote:

>
> I have a window with a central layout, when I press  a button in central
> widget, I want to remove this layout/widgets(?) and in the SLOT callback
> code populate the central area with a new set of Widgets ( or new layout, a
> form with QLineEdits, and labels and 1 or 2 buttons to 'save' and return').
>  But maybe this is in _general_ the wrong way of going about it!
>
> I'm able to remove the central widget using either of the following lines
> in my callback SLOT function:
>
>
> CustomCentalWidget::close();
> or
> CustomCentralWidget::QWidget::hide();
>
>
> But if I create a new QGroupBox and a QVBoxLayout and add widgets to this
> layout I can't get  them to show up.
>
> References:
> The button calling the _slot_ code:
>
> CentralPage::CentralPage(QWidget *parent)
>     : QWidget(parent)
> {
> ....
> connect( addExperimenterButton, SIGNAL( clicked() ), this,\
>              SLOT( addExperimenterSlot() ) );
> }
>
>
> I have simplified the callback  code to see if I can get something to show
> up:
>
> bool CentralPage::addExperimenterSlot(void)
>
> {
>
>     //CentralPage::QWidget::hide();
>
>     CentralPage::close();
>
>
>
>     QPushButton *addExp2dbButton = new QPushButton(this, tr("Add") );
>
>     addExp2dbButton->show();
>
>     //this->show();
>
>
>
>     return 1;
>
> }
>
>
> What I end up with is with an empty central widget:
> +------------------------+
> | north Widget Group Box |
> +------------------------+
> |                        |
> |   (central widget)     |
> |                        |
> +------------------------+
> | South Widget Group     |
> +------------------------+
>
> So,
> 1. How can I add new widgets to the central widget from a private/public
> SLOT?
> 2. Is what I want to do the right way of going about it?
>
> References:
> Re: [Qt-interest] Problem with adding/removing/adding elements in a
> QVBoxLayout
> ------------------------------
>
>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090730/60dfc673/attachment.html 


More information about the Qt-interest-old mailing list