You create a new widget at run time using the C++ new operator with an appropriate class, e.g. MyCustomFrame or QLabel. You call the layout object's addWidget() function with your newly minted widget. All this happens in the slot you have connected to the clicked() signal of the QPushButton.
Assuming the widgets are being added to the layout of your main window it might look like this:
// mainwindow.h
class MainWindow: ...
{
...
public slots:
void on_pushbutton_clicked();
...
};
// mainwindow.cpp
void on_pushbutton_clicked()
{
MyCustomFrame *frame = new MyCustomFrame(this);
ui->verticalLayout->addWidget(frame);
// do other init stuff
}
// mainwindow.h
class MainWindow: ...
{
...
public slots:
void on_pushbutton_clicked();
...
};
// mainwindow.cpp
void on_pushbutton_clicked()
{
MyCustomFrame *frame = new MyCustomFrame(this);
ui->verticalLayout->addWidget(frame);
// do other init stuff
}
To copy to clipboard, switch view to plain text mode
Bookmarks