Hi Gunnar,

Thanks for your help. I got some ideas from your previous advice and it
seems like I have fixed the problem with the windows not opening after I
closed them. I just put the set of widgets that the QMdiSubWindow was
supposed to contain in their own class (extending QMdiSubWindow) and
implemented a simple close event, and it works now (except for a certain
NullPointerException that I can live with, and maybe fix one of those days).
So now I have several classes that return QMdiSubWindows, which I use to
populate the mdiarea, and said subwindows are properly opened and closed
thanks to this:

    public void closeEvent(QCloseEvent event) {
           this.mdiArea().activeSubWindow().widget().close();
           event.accept();
    }

Alas, for some reason the QMdiSubWindow does not display the internal widget
now. Here's an example of what I'm doing:

package plugin;

//imports go here

public class SimpleResponseTestDialog extends QMdiSubWindow{

//variables go here

    public SimpleResponseTestDialog() {
        test.setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose);
        testButton.clicked.connect(this, "changeMode()");
        trainingButton.clicked.connect(this, "changeModeTraining()");
        testButton.setDefault(true);
        trainingButton.setAutoDefault(false);
        buttons.addButton(testButton,
QDialogButtonBox.ButtonRole.ActionRole);
        buttons.addButton(trainingButton,
QDialogButtonBox.ButtonRole.ActionRole);

        //Make the view bigger
        view.resize(400, 400);

        //Put everything together
        testMainLayout.addWidget(view);
        testMainLayout.addWidget(buttons);
        test.setLayout(testMainLayout);
    }

    public void closeEvent(QCloseEvent event) {
           this.mdiArea().activeSubWindow().widget().close();
           event.accept();
    }

With this, when I want to add a subwindow I just call a method that creates
an object of the corresponding class, and I pass that object to another
method that adds it to the mdiarea and shows the subwindow (or makes it
active if it already exists), like this:

    public QMdiSubWindow showTest() {
        SimpleResponseTestDialog srtd = new SimpleResponseTestDialog();
        return srtd;
    }

private void addNewSubWindow(QMdiSubWindow window, String title) {
        if (findMdiChild(title)!=null) {
            mdiArea.setActiveSubWindow(findMdiChild(title));
        } else {
            window.setWindowTitle(title);
            mdiArea.addSubWindow(window);
            window.show();
            //window.widget().show();
        }
    }

    public QMdiSubWindow findMdiChild(String title) {
        for(QMdiSubWindow window : mdiArea.subWindowList()) {
            if (window.windowTitle().equals(title)) {
                return window;
            }
        }
        return null;
    }

But as I said, window.show() shows the QMdiSubWindow, and not its contents.
Just the frame and decoration (title bar with buttons to maximize, minimize
and close). If I call window.widget().show() nothing shows, not even the
frame and decoration of the subwindow. I'll be working on it (can't be much
more difficult than calling the right method at the right time, can it?),
but as always, I'd appreciate any and all help I can get.
_______________________________________________
Qt-jambi-interest mailing list
[email protected]
http://lists.trolltech.com/mailman/listinfo/qt-jambi-interest

Reply via email to