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

PySide – PyQt : How to make set QTableWidget column width as proportion of the available space?

This can be solved by setting the resize-mode for each column. The first section must stretch to take up the available space, whilst the last two sections just resize to their contents: PyQt5: header = self.table.horizontalHeader() header.setSectionResizeMode(0, QHeaderView.Stretch) header.setSectionResizeMode(1, QHeaderView.ResizeToContents) header.setSectionResizeMode(2, QHeaderView.ResizeToContents) PyQt6/PyQt5: header = self.table.horizontalHeader() header.setSectionResizeMode(0, QHeaderView.ResizeMode.Stretch) header.setSectionResizeMode(1, QHeaderView.ResizeMode.ResizeToContents) header.setSectionResizeMode(2, QHeaderView.ResizeMode.ResizeToContents) PyQt4: header = … Read more

PyQt or PySide – which one to use [closed]

Both toolkits are actively maintained, and by now more or less equal in features and quality. There are only few, rather unimportant differences. Still, I’d recommend PySide for Python 2. It has a more reasonable API, mainly it doesn’t expose Qt types, which have a direct equivalent in Python (e.g. QString, QList, etc.) or which … Read more