N
N
nvlveu2020-11-06 19:04:55
Python
nvlveu, 2020-11-06 19:04:55

How to track window resizing in PyQt5?

Hello. I am writing a program in PyQt5. It came down to a function that should fire every time the window is resized. No matter how much I "borrowed" the code from the answers on various forums on this issue - none of them work.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor T2, 2020-11-06
@nvlveu

Working example:

import sys
from PyQt5 import QtCore, QtGui
from PyQt5.QtWidgets import QApplication, QMainWindow


class Window(QMainWindow):
    
    resized = QtCore.pyqtSignal()   # 1
    
    def __init__(self):
        super(Window, self).__init__()

        self.resized.connect(self.someFunction)   # 2
        
    def resizeEvent(self, event):
        self.resized.emit()
        return super(Window, self).resizeEvent(event)

    def someFunction(self):
        print("someFunction")        


if __name__ == '__main__':

    app = QApplication(sys.argv)
    window = Window()
    window.setGeometry(300, 100, 600, 600)
    window.show()
    sys.exit(app.exec_())

From here:
https://stackoverflow.com/questions/43126721/detec...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question