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

Malyushytsky, Alex alex at wai.com
Fri Jul 31 00:50:59 CEST 2009


First I would recommend you send message only to the mailing list, not replying to the other people directly and don't put in your message part of the conversation about other topic in the list.
It is not that difficult to create a new message and type qt-interest at trolltech.com there, avoid replying to the other people messages as you done in your first post.

I assume your central widget has a layout.
That layout have some widgets added to it.
You want to replace such widgets with another widgets.


So, you might
 1. delete the widgets widgets and layouts you don'te need:

   Use operator "delete". In case of QWidget* w = new ....;
   delete w; will delete the widget.

 2 create another widgets
    QPushButton *addExp2dbButton = new QPushButton(this, tr("Add") );   // you did it

 3. add new widget to the layout of the central widget. (that what you did not do).

     How you do it, depends does or does not the parent widget has already layout set. I assume it does cause you said you want to replace widgets. So You can use QLayout * QWidget::layout () to get layout.
Or create a new one layout, delete the old layout and set it to the central widget similar to the way old widgets were added.

You might need to call layout->update(), if you are doing this when parent widget was visible.
No need to call close() or hide on parent or any other widget.
 If you delete to add multiple widgets you might want to disable parent widget update with
void QWidget::setUpdatesEnabled ( bool enable ) before change and set it to true after to avoid blinking.

Hope this helps,
  Alex


From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of S. Aguinaga
Sent: Thursday, July 30, 2009 1:35 PM
To: S. Aguinaga; Karol Krizka; Juan Pablo Crossley
Cc: qt-interest at trolltech.com
Subject: [Qt-interest] swap out "central" layout when button is pressed with new widgets


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
________________________________________




---------------------------------------------------------------------------------------------------
Weidlinger Associates, Inc. made the following annotations.

"This message and any attachments are solely for the intended recipient and may contain confidential or privileged information. If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank you."

"Please consider our environment before printing this email."




More information about the Qt-interest-old mailing list