M
M
MrZed2020-11-19 23:57:09
PyQt
MrZed, 2020-11-19 23:57:09

PyQt5 Track window resizing?

How to track window resizing?
Found the code here :

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


How to move the function to my code:
from PyQt5 import QtCore, QtGui, QtWidgets
import sys

class Ui_Form(object):
    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(650, 450)
        self.pushButton = QtWidgets.QPushButton(Form)
        self.pushButton.setGeometry(QtCore.QRect(120, 160, 391, 111))
        self.pushButton.setObjectName("pushButton")

        self.retranslateUi(Form)
        QtCore.QMetaObject.connectSlotsByName(Form)

    def retranslateUi(self, Form):
        _translate = QtCore.QCoreApplication.translate
        Form.setWindowTitle(_translate("Form", "Form"))
        self.pushButton.setText(_translate("Form", "PushButton"))

app = QtWidgets.QApplication(sys.argv)
Form = QtWidgets.QWidget()
ui = Ui_Form()
ui.setupUi(Form)
Form.show()

# Тут код программы


sys.exit(app.exec_())

I didn't explain it very well, but I hope it's clear.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ronald McDonald, 2020-11-20
@Zoominger

self.resized.connect(self.someFunction)
This is the fuss in setupUi, throw your function on it. Everything.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question