def __add__(self, widget): """ Show widget on mdi area. If widget does not have a subwindow assigned, create a new subwindow without enabling the WA_DeleteOnClose event. This will allow subwindow to be hidden instead of destroyed. Otherwise, the closeEvent.accept() will cause the "Internal c++ Object Already Deleted" problem. If widget already has a subwindow, just show them (both the subwindow and the widget inside)! :param widget: :return: """ if not hasattr(widget, 'subwindow'): subwindow = QMdiSubWindow() subwindow.setWidget(widget) rect = widget.geometry() # DO NOT SET ATTRIBUTE WA_DeleteOnClose because we want window not to be destroyed widget.subwindow = self.addSubWindow(subwindow) subwindow.setGeometry(rect) widget.subwindow.show() widget.show() widget.closeEvent = lambda x: self._subWindowClosed(x) widget.setFocus() logger.debug("Sub window opened. MDI area sub windows: %s", self.subWindowList()) return self
def create_widget(self): """ Create the underlying QMdiSubWindow widget. """ # We don't parent the subwindow immediately. It will be added # explicitly by the parent QMdiArea during its layout pass. # If we set the parent here, Qt will spit out warnings when # it's set added to the area later on. We *could* parent it # here, and simply not add it explicitly to the mdi area, but # this way is more explicit and consistent with the rest of # the framework. widget = QMdiSubWindow() widget.layout().setSizeConstraint(QLayout.SetMinAndMaxSize) self.widget = widget