pyqt4 window resize event

chicken-me picture chicken-me · Dec 11, 2016 · Viewed 10k times · Source

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.

Answer

eyllanesc picture eyllanesc · Mar 2, 2017

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_())