Source code for enaml.qt.qt_mdi_window
#------------------------------------------------------------------------------
# Copyright (c) 2012, Enthought, Inc.
# All rights reserved.
#------------------------------------------------------------------------------
from .qt.QtGui import QMdiSubWindow, QLayout
from .qt_widget import QtWidget
[docs]class QtMdiWindow(QtWidget):
""" A Qt implementation of an Enaml MdiWindow.
"""
#--------------------------------------------------------------------------
# Setup Methods
#--------------------------------------------------------------------------
[docs] def init_layout(self):
""" Initialize the layout for the underlying control.
"""
super(QtMdiWindow, self).init_layout()
self._set_window_widget(self.mdi_widget())
#--------------------------------------------------------------------------
# Utility Methods
#--------------------------------------------------------------------------
[docs] def child_removed(self, child):
""" Handle the child removed event for a QtMdiWindow.
"""
if isinstance(child, QtWidget):
self._set_window_widget(self.mdi_widget())
[docs] def child_added(self, child):
""" Handle the child added event for a QtMdiWindow.
"""
if isinstance(child, QtWidget):
self._set_window_widget(self.mdi_widget())
#--------------------------------------------------------------------------
# Private API
#--------------------------------------------------------------------------
def _set_window_widget(self, mdi_widget):
""" A private method which set the child widget on the window.
Parameters
----------
mdi_widget : QWidget
The child widget to use in the mdi window.
"""
# We need to first set the window widget to None, or Qt will
# complain if a widget is already set on the window.
widget = self.widget()
widget.setWidget(None)
if mdi_widget is None:
return
# We need to unparent the underlying widget before adding
# it to the subwindow. Otherwise, children like QMainWindow
# will persist as top-level non-mdi widgets.
mdi_widget.setParent(None)
widget.setWidget(mdi_widget)
# On OSX, the resize gripper will be obscured unless we
# lower the widget in the window's stacking order.
mdi_widget.lower()