PDA

View Full Version : Bug with QMdiSubWindow Close window flag, or am I doing this wrong?



MachinTrucChose
25th November 2011, 20:17
Summary: I have a MainWindow with an MDI area within which I want to place subwindows (QWidgets). I would like these subwindows to have a Minimize and a Close button, i.e. no Maximize button. My problem is that I can't get the Close button to show up no matter what I do. It's like the flag is ignored on MDI subwindows.

First, I realized that doing myqwidget->setWindowFlags(myflags) did not do anything anymore. Regardless of what flags I specify, they are ignored and "default" flags are used. The MDI area requires you to set flags on the QMdiSubWindow, not the QWidget it represents.

No biggie, because I just used


QMdiSubWindow *sub = ui->mdiArea->addSubWindow(myqwidget);
sub->setWindowsFlags(myflags);


The above does set flags, EXCEPT for the Close flag. In other words when I do this:


Qt::WindowFlags flags;
flags |= Qt::WindowCloseButtonHint;
flags |= Qt::WindowMinimizeButtonHint;
sub->setWindowFlags(flags);


Only the Minimize button appears. I have tried every flag variation I could think of (including only using CloseButton), to no avail. In a non-MDI window, the CloseButtonHint of course works fine.

I'm not sure if this is a bug I should report or intended behaviour. I spent 2 hours reading the doc and I couldn't find any mention of special Close flag behavior for MDI subwindows. I figured I'd ask here to get confirmation before I bother the Qt team with a bug report. What do you guys think?

I've attached a basic project that demonstrates this. All the code is in MainWindow's constructor.

norobro
25th November 2011, 23:49
From the docs (http://doc.qt.nokia.com/latest/qt.html#WindowType-enum):
Adds a close button. On some platforms this implies Qt::WindowSystemMenuHint for it to work.
On Linux :D the following works:
subwindow->setWindowFlags(Qt::WindowMinimizeButtonHint| Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint);