PDA

View Full Version : Weird behaviour with QMdiSubWindows in a QMdiArea?



qt_noob
2nd April 2009, 07:32
Hi,

I'm working on a project using Qt Jambi, and I have come across something has me stumped, even though I have checked all the documentation and examples I could find (even C++ ones despite using Java).

The GUI for the application I'm working on shows a QListView and a QMdiArea, and when the user selects an option in the list, a QMdiSubWindow should appear in the QMdiArea.
The problem is, it does indeed appear... But only once. That is, if I close the subwindow and then click once again in the same option of the list, nothing happens. Furthermore, if I leave the subwindow open and click on the same option, a new subwindow appears, and the other remains open but content-less (the widget that it displayed disappears). This second issue is not really important since the user won't need a second instance of the same subwindow due to what the application does.

So, how am I supposed to handle subwindows in this case? Specifically, how do I close a subwindow and make it appear again as needed?
Currently I'm adding them by calling methods of classes that return a Qwidget (which contains other widgets conveniently put into layouts so it doesn't look ugly), and passing that widget to another method that puts it in a QMdiSubWindow and adds it to the QMdiArea. I haven't reimplemented the close event for the subwindows since I'm not subclassing QMdiSubWindow and it looks strange to imlement it in the class that provides the previously mentioned methods that return a QWidget. The close event in the main window (which houses the QMdiArea) looks like this:


public void closeEvent(QCloseEvent event) {
//writeSettings();
mdiArea.closeAllSubWindows();
if (!mdiArea.subWindowList().isEmpty()) {
event.ignore();
} else {
event.accept();
}
}

And the way I add the subwindows is as follows:


private void addNewSubWindow(QWidget widget, String title) {
mdiArea.hide();
QMdiSubWindow window = mdiArea.addSubWindow(widget);
window.setWindowTitle(title);
window.setAttribute(Qt.WidgetAttribute.WA_DeleteOn Close);
mdiArea.show();
}

Any ideas?

qt_noob
3rd April 2009, 07:23
Guess I'll have to bump the thread so people don't miss it and can offer some help.

As an update to my previous post, I've been told to check if my problems are due to something like making references to the QMdiSubWindows that I close, 'cause then they wouldn't get properly deleted, which could cause the behaviour I'm experiencing. I'll do that later and post again if it solves anything, if only to help others that may come across the same thing.

qt_noob
4th April 2009, 16:48
I'll do that later and post again if it solves anything, if only to help others that may come across the same thing.

Checked that, found nothing. Apparently, the subwindows are not being referenced when they shouldn't be, so unwanted references are not the cause of the problem here.

Does anyone have any idea of what might be going on? Maybe an example of how to properly use QMdiArea (the one in the Qt Jambi documentation (http://doc.trolltech.com/qtjambi-4.4/html/com/trolltech/qt/qtjambi-mdi.html) is kind of useless, what with it lacking source)... I tried to adapt from the Qt one (that is, the C++ one), but that clearly wasn't enough.