1
votes

I have the following custom widget:

QBrowserContainer::QBrowserContainer(QWidget *parent) :
    QWidget(parent)
{

    QPushButton *test= new  QPushButton("Test",this);

    // ----> layout()->addWidget(test);
} 

In Qt creator i promoted a QWidget to QBrowserContainer.

in the commented line i add a widget to the layout but i cannot do this because we don't have yet a layout, is added in setupUI after QBrowserContainer creation. So my question is: is there any event that is triggered when a layout is added to a widget, so i can add the widget to the layout created?

I know that i can create a layout and add the widget like this:

QBrowserContainer::QBrowserContainer(QWidget *parent) :
        QWidget(parent)
    {

        QPushButton *test= new  QPushButton("Test",this);

        QHBoxLayout* pLayout = new QHBoxLayout(this);
        pLayout->addWidget(test);

    } 

but i want to use the layout created by the designer (created by SetupUI()).

Thanks

1

1 Answers

1
votes

You can access the layout created in designer through ui->. For instance if it is a QGridLayout then by default it's name is gridLayout :

ui->gridLayout->addWidget(test);

You can check the name in designer.