Raúl wrote:
> 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).
Hi,
There is an example for C++ in the examples/mainwindows/mdi directory in
the Qt C++ package.
> 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 Qwidget 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.
>
> Source for the only close event I implemented (the one for the main
> window) is like this:
>
> public void closeEvent(QCloseEvent event) {
> //writeSettings();
> mdiArea.closeAllSubWindows();
> if (!mdiArea.subWindowList().isEmpty()) {
> event.ignore();
> } else {
> event.accept();
> }
> }
This seems like quite an overkill, and would look very wrong if you have
multiple active mdi windows.
> And the method to create and add a subwindow 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();
> }
why are you hiding and showing the mdiarea? This makes no sense to me.
I think the major problem here is that you don't store the reference to
the actual window. The code above discards the QMdiSubWindow pointer. I
suspect when you say you call close and hide you do so on the widget.
Internally, the QMdiArea::addSubWindow() will wrap your widget into a
QMdiSubWindow, so the pointers are not the same (unless your widget
happens to be a QMdiSubWindow). When you call close you will only close
your widget, not the actual sub window, which would explain why you have
blank windows staying behind. So the solution would be to talk to the
window, not your own content widget for the mdi spesific logic.
_______________________________________________
Qt-jambi-interest mailing list
[email protected]
http://lists.trolltech.com/mailman/listinfo/qt-jambi-interest