What are good practices for avoiding crashes / hangs in PyQt?

General Programming Practices If you must use multi-threaded code, never-ever access the GUI from a non-GUI thread. Always instead send a message to the GUI thread by emitting a signal or some other thread-safe mechanism. Be careful with Model/View anything. TableView, TreeView, etc. They are difficult to program correctly, and any mistakes lead to untraceable … Read more

PySide / PyQt detect if user trying to close window

Override the closeEvent method of QWidget in your main window. For example: class MainWindow(QWidget): # or QMainWindow … def closeEvent(self, event): # do stuff if can_exit: event.accept() # let the window close else: event.ignore() Another possibility is to use the QApplication‘s aboutToQuit signal like this: app = QApplication(sys.argv) app.aboutToQuit.connect(myExitHandler) # myExitHandler is a callable

How to install PyQt4 in anaconda?

Updated version of @Alaaedeen’s answer. You can specify any part of the version of any package you want to install. This may cause other package versions to change. For example, if you don’t care about which specific version of PyQt4 you want, do: conda install pyqt=4 This would install the latest minor version and release … Read more

Debugging a pyQT4 app?

You need to call QtCore.pyqtRemoveInputHook. I wrap it in my own version of set_trace: def debug_trace(): ”’Set a tracepoint in the Python debugger that works with Qt”’ from PyQt4.QtCore import pyqtRemoveInputHook # Or for Qt5 #from PyQt5.QtCore import pyqtRemoveInputHook from pdb import set_trace pyqtRemoveInputHook() set_trace() And when you are done debugging, you can call QtCore.pyqtRestoreInputHook(), … Read more