Here is what I am doing: mainwindow with MdiArea, and I add a scrollarea widget (which contains a image label) to MdiArea as a subwindow. It doesn't work (the picture doesn't show).
Here is my code:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QScrollArea sa;
QPixmap *image = new QPixmap("2.jpg");
QLabel* imageLabel = new QLabel();
imageLabel->setPixmap(*image);
sa.setWidget(imageLabel);
sa.show();
ui->mdiArea->addSubWindow(&sa);
}
But when I use a QLabel
as subwindow directly, i.e. replace the last line with:
ui->mdiArea->addSubWindow(imageLabel);
it works perfectly.
Anyone know why this is happening?
This declares a
QScrollArea
on the stack. It gets destroyed immediately after the constructor finishes. Allocate it withnew
like you do for the other widgets and it should start working.(And change the
sa.
tosa->
.)