python - How does PySide/PyQt QMainWindow close a QDockWidget? -
i need know how qdockwidget closed. have serial port/thread attached qdockwidget, , need make sure thread , serial port close properly.
class serialdock(qdockwidget): ... def close(self): print("close") self.serialport.close() self.thread.close() def closeevent(self, event): print("closeevent") self.serialport.close() self.thread.close()
the close , closeevents not called when click qmainwindow x button. have call close method qmainwindow close? way know solve use qapplication.abouttoquit signal, , don't want have remember set 1 specific widget. how qdockwidget destroyed or closed?
you can use destroyed
signal in qdockwidget
:
import pyqt4.qtgui ui import pyqt4.qtcore core app = ui.qapplication([]) mw = ui.qmainwindow() mw.setcentralwidget(ui.qtextedit()) dw = ui.qdockwidget("test",mw) dw.setwidget(ui.qlabel("content")) mw.adddockwidget(core.qt.rightdockwidgetarea, dw) def ondestroy(w): print("do stuff here") print(w) dw.destroyed.connect(ondestroy) mw.show() app.exec_()
Comments
Post a Comment