I'm using python3 and pyqt4 and I want some code to run every time my QMainWindow is resized.I would like something like this
self.window.resized.connect(self.resize)
but resized is not a builtin function or method.
Can anyone help.
You must override the resizeEvent method.
from PyQt4 import QtCore, QtGui
import sys
class MainWindow(QtGui.QMainWindow):
    def resizeEvent(self, event):
        print("resize")
        QtGui.QMainWindow.resizeEvent(self, event)
app = QtGui.QApplication(sys.argv)
w = MainWindow()
w.show()
sys.exit(app.exec_())
                        For anyone who is looking for it, here is a PyQt5 solution. This is pretty much @eyllancesc code, so all thanks goes to them. There are only a few modifications needed for PyQt5
from PyQt5 import QtCore, QtGui, QtWidgets
import sys
class MainWindow(QtWidgets.QMainWindow):
    def resizeEvent(self, event):
        print("Window has been resized")
        QtWidgets.QMainWindow.resizeEvent(self, event)
app = QtWidgets.QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With