PDA

View Full Version : Subclassing QMdiSubWindow and maximize/minimize problems



googie
25th June 2013, 01:02
Hi,

I have simple "Main window" application, straight from QtCreator wizard. I added QMdiArea as a center widget.

As a first test I created new Qt Form (using wizard), which inherits from QWidget. I reimplemented sizeHint() to return some reasonable size, like 200x200.
Then I added to MainWindow's constructor few lines, so it looked like:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);

Form* f = new Form(this);
ui->mdiArea->addSubWindow(f);
}

I've started the application and it worked as expected. There was the MDI window and I could move it, resize and maximize it.

Now, as a second test I changed Form class to inherit from QMdiSubwindow, instead of QWidget (in both *.h and *.cpp files, but the *.ui file was not changed). I also modified Form constructor, in order to respect the new container for setupUi:
setWidget(new QWidget(this));
setAttribute(Qt::WA_DeleteOnClose);
ui->setupUi(widget());
I expected that QMdiArea should accept the Form instance now just like before, because the documentation says that I can pass either QMdiSubWindow or any other QWidget to QMdiArea::addSubWindow().

This actually works pretty much okay - Form is being added to MDI area and I can move and resize it, but the problem is I cannot maximize it. When I press "maximize" button on the MDI window, the button stays pushed, never pops up and the window doesn't maximize.

What do I do wrong?