Results 1 to 3 of 3

Thread: Weird behaviour with QMdiSubWindows in a QMdiArea?

  1. #1
    Join Date
    Feb 2009
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Weird behaviour with QMdiSubWindows in a QMdiArea?

    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:

    Qt Code:
    1. public void closeEvent(QCloseEvent event) {
    2. //writeSettings();
    3. mdiArea.closeAllSubWindows();
    4. if (!mdiArea.subWindowList().isEmpty()) {
    5. event.ignore();
    6. } else {
    7. event.accept();
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 

    And the way I add the subwindows is as follows:

    Qt Code:
    1. private void addNewSubWindow(QWidget widget, String title) {
    2. mdiArea.hide();
    3. QMdiSubWindow window = mdiArea.addSubWindow(widget);
    4. window.setWindowTitle(title);
    5. window.setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose);
    6. mdiArea.show();
    7. }
    To copy to clipboard, switch view to plain text mode 

    Any ideas?

  2. #2
    Join Date
    Feb 2009
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Weird behaviour with QMdiSubWindows in a QMdiArea?

    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.

  3. #3
    Join Date
    Feb 2009
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Weird behaviour with QMdiSubWindows in a QMdiArea?

    Quote Originally Posted by qt_noob View Post
    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 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.

Similar Threads

  1. Weird behavior when readding a window to a QMdiArea
    By seand in forum Qt Programming
    Replies: 0
    Last Post: 27th August 2008, 03:14
  2. Weird behaviour of mouse events and QMenu pop-ups
    By Ishark in forum Qt Programming
    Replies: 1
    Last Post: 7th August 2007, 08:46
  3. Model/View weird behaviour - Windows/Mingw
    By incapacitant in forum Newbie
    Replies: 7
    Last Post: 23rd March 2006, 23:21

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.