I have two open MainWindows: MainWindowWithButton and MainWindowWithDock. The later contains a QDockWidget.
IS behaviour: When the users makes the DockWidget floatable and closes MainWindowWithDock, the dockWidget doesn't close.
SHOULD behaviour: When the users makes the DockWidget floatable and closes MainWindowWithDock, the dockWidget closes as well.
Notes:
- Reason for "IS behaviour": A floating DockWidget seems to be independent from it's parent
- I cannot listen for onClose / reject (as it will give false information in my particular case.
- The MainWindow does not emit clear signals about it's behaviour
- It is important, that the DockWidget closes before the MainWindow closed. Otherwise the focus goes unexpected
Example code :
from PyQt4 import QtCore, QtGui
from PyQt4 import QtCore, QtGui
from PyQt4.QtGui import QApplication, QDialog, QMainWindow
import sys
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_MainWindowWithButton(object):
def setupUi(self, MainWindowWithButton):
MainWindowWithButton.setObjectName(_fromUtf8("MainWindowWithButton"))
MainWindowWithButton.resize(567, 384)
self.centralwidget = QtGui.QWidget(MainWindowWithButton)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
MainWindowWithButton.setCentralWidget(self.centralwidget)
def retranslateUi(self, MainWindowWithButton):
MainWindowWithButton.setWindowTitle(_translate("MainWindowWithButton", "MainWindow", None))
class Ui_MainWindowWithDock(object):
def setupUi(self, MainWindowWithDock):
MainWindowWithDock.setObjectName(_fromUtf8("MainWindowWithDock"))
MainWindowWithDock.resize(509, 316)
self.centralwidget = QtGui.QWidget(MainWindowWithDock)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
MainWindowWithDock.setCentralWidget(self.centralwidget)
# # # # # # # # # # # # # # # # # # # # # #
# # # setup dock # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # #
self.theDock = QtGui.QDockWidget(MainWindowWithDock)
self.theDock.setObjectName(_fromUtf8("theDock"))
self.dockWidgetContents = QtGui.QWidget(self.theDock)
self.dockWidgetContents.setObjectName(_fromUtf8("dockWidgetContents"))
self.theDock.setWidget(self.dockWidgetContents)
MainWindowWithDock.addDockWidget(QtCore.Qt.DockWidgetArea(2), self.theDock)
self.retranslateUi(MainWindowWithDock)
QtCore.QMetaObject.connectSlotsByName(MainWindowWithDock)
def retranslateUi(self, MainWindowWithDock):
MainWindowWithDock.setWindowTitle(_translate("MainWindowWithDock", "MainWindow", None))
class MainWindowWithButtonDlg(QMainWindow):
pass
class MainWindowWithDockDlg(QMainWindow):
pass
def main():
app = QApplication(sys.argv)
windowWithDockUi = Ui_MainWindowWithDock()
windowWithDock = MainWindowWithDockDlg()
windowWithDockUi.setupUi(windowWithDock)
windowWithDock.show()
app.exec()
# the dock widget should be closed by now
ui = Ui_MainWindowWithButton()
window = MainWindowWithButtonDlg()
ui.setupUi(window)
window.show()
app.exec()
if __name__ == '__main__':
main()
reject method of the original Source. Here we have a QDialog with a QMainwindow as it's central Widget - therefore it becomes a QMainWindow in some sense(from Anki addCards.py (scroll to bottom):
def reject(self):
if not self.canClose(): # this way of calling is basically the problem: we might leave this method without doing anything
return
remHook('reset', self.onReset)
remHook('currentModelChanged', self.onModelChange)
clearAudioQueue()
self.removeTempNote(self.editor.note)
self.editor.setNote(None)
self.modelChooser.cleanup()
self.deckChooser.cleanup()
self.mw.maybeReset()
saveGeom(self, "add")
aqt.dialogs.close("AddCards")
QDialog.reject(self)