Important: Please read the Qt Code of Conduct -

Prevent QMdiArea object from removing QMdiSubWindow when user clicks close button

  • I want the hide the sub window and not remove it when the user clicks the close button on the sub window. How do I prevent the QMdiArea object from removing this object?

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    From the top of my head: subclass QMdiSubWindow and reimplement it's closeEvent to hide rather than close.

    Hope it helps

  • I know two ways to do it:

    1. Hidde the close button of the QMdiSubWindow:
      @subwindow->setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowMinMaxButtonsHint);@

    2. Avoid the close accion re-writing the close event of the QWidget of the subwindow:
      @void YourWidget::closeEvent(QCloseEvent *e)

Log in to reply