This is what the object inspector currently looks like
7.PNG
in form ui
8.jpg
I put the scroll area at the second page of the stacked widget. On this page, there is a little vertical layout on the top left corner and a scroll area at the right side. I made a function for that "add" function.
void MainWindow::on_pushButton_2_clicked(){
ui->scrollArea->setWidgetResizable(true);
ui->scrollAreaWidgetContents->setLayout(layout);
ui->scrollArea->ensureWidgetVisible(ui->scrollAreaWidgetContents);
// to add my custome widget
ui->scrollAreaWidgetContents->layout()->addWidget(new modal(this));
ui->scrollArea->ensureWidgetVisible(ui->scrollAreaWidgetContents);
}
void MainWindow::on_pushButton_2_clicked(){
ui->scrollArea->setWidgetResizable(true);
ui->scrollAreaWidgetContents->setLayout(layout);
ui->scrollArea->ensureWidgetVisible(ui->scrollAreaWidgetContents);
// to add my custome widget
ui->scrollAreaWidgetContents->layout()->addWidget(new modal(this));
ui->scrollArea->ensureWidgetVisible(ui->scrollAreaWidgetContents);
}
To copy to clipboard, switch view to plain text mode
"QScrollArea so that it contains a QWidget as the widget it controls, and that widget contains a QVBoxLayout "
I'm not sure what QWidget should this be, but I assume that it is the scrollAreaWidgetContent.
So I wrote the line " ui->scrollAreaWidgetContents->setLayout(layout); " as you mentioned "and that widget contains a QVBoxLayout that you are adding the copies of your custom widget to"
and finally, I wrote the line to invoke ensureWidgetVisible(). But the widgets still got squashed.
When I run the program it says "QLayout: Attempting to add QLayout "" to MainWindow "MainWindow", which already has a layout". I assume this is because I tried to put 2 layouts on the same page of the stackedWidget?
I am not sure if I have to call all those items via stackedWidget such as "ui->stackedWidget->page_2->scrollArea->...."
I need more help from you. Thanks in advance.
Bookmarks