Results 1 to 5 of 5

Thread: Close a QMdiSubwindow

  1. #1
    Join Date
    Sep 2007
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Close a QMdiSubwindow

    Hi,

    Is there a way to close a QMdiSubwindow using the central widget?

    In the MDI example, child->close() is called but this leaves the QMdiSubwindow in the QMdiArea subWindowList. I would like to call close() on the QMdiSubwindow so it is removed from the subWindowList but I can't find a way to obtain the QMdiSubwindow from the central widget.

    Thanks.

    John

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Close a QMdiSubwindow

    Delete the widget afterwards. close() only hides it, not destroyes it, thus it's still in the list.

  3. #3
    Join Date
    Sep 2007
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Close a QMdiSubwindow

    Thanks Wysota for your quick reply. My child widget has the attribute WA_DeleteOnClose so I presume child->close() will have deleted it.

    Anyway, I found a way to get the QMdiSubWindow from the child as

    QMdiSubWindow* QMdiChild = qobject_cast<QMdiSubWindow*>(child->parentWidget());

    Calling QMdiChild->close() deletes the central widget AND the mdi subwindow so I am happy.

    Thanks again,

    John.

  4. #4
    Join Date
    Jul 2006
    Location
    Atlanta, GA
    Posts
    86
    Thanks
    26
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Close a QMdiSubwindow

    I have been having the same problem. I thought doing the setAttribute(Qt::WA_DeleteOnClose) would delete the sub window when you call a close(), but it is not for me. Am I doing this wrong?

    Qt Code:
    1. void nnDBSMainWindow::pieceEntry()
    2. {
    3. nnDBSPieceEntry *pieceEntry = new nnDBSPieceEntry;
    4. QMdiSubWindow *swPieceEntry = new QMdiSubWindow;
    5. swPieceEntry->setWidget(pieceEntry);
    6. MDIArea->addSubWindow(swPieceEntry);
    7. swPieceEntry->setAttribute(Qt::WA_DeleteOnClose);
    8. swPieceEntry->setWindowFlags(Qt::WindowTitleHint);
    9. swPieceEntry->show();
    10. swPieceEntry->resize(650, 600);
    11. }//End pieceEntry
    To copy to clipboard, switch view to plain text mode 
    fnmblot
    --------------------------------------
    Gee Ricky, I'm sorry your mom blew up.

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Close a QMdiSubwindow

    As John_P mentioned, it's not enough to call pieceEntry->close() but you have to call swPieceEntry->close().
    J-P Nurmi

Similar Threads

  1. Disable Close button (X) of a QDialog
    By BrainB0ne in forum Qt Programming
    Replies: 29
    Last Post: 8th December 2009, 18:01
  2. when close QTextStream
    By mattia in forum Newbie
    Replies: 1
    Last Post: 24th November 2007, 14:17
  3. Replies: 3
    Last Post: 16th November 2006, 13:24
  4. Replies: 3
    Last Post: 23rd July 2006, 19:02
  5. Qmenu Stable close on QTableWidget
    By patrik08 in forum Qt Programming
    Replies: 1
    Last Post: 17th July 2006, 11:03

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.