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:
//writeSettings();
mdiArea.closeAllSubWindows();
if (!mdiArea.subWindowList().isEmpty()) {
event.ignore();
} else {
event.accept();
}
}
public void closeEvent(QCloseEvent event) {
//writeSettings();
mdiArea.closeAllSubWindows();
if (!mdiArea.subWindowList().isEmpty()) {
event.ignore();
} else {
event.accept();
}
}
To copy to clipboard, switch view to plain text mode
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_DeleteOnClose);
mdiArea.show();
}
private void addNewSubWindow(QWidget widget, String title) {
mdiArea.hide();
QMdiSubWindow window = mdiArea.addSubWindow(widget);
window.setWindowTitle(title);
window.setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose);
mdiArea.show();
}
To copy to clipboard, switch view to plain text mode
Any ideas?
Bookmarks