I made a simple first application on python, everything would be fine, but the resizeEvent function is loaded and because of that when scaling the window it slows down, the fact is that this function has such code:

 def resizeEvent(self, event): self.lbl.setGeometry(QRect(0, 0, self.width(), self.height())) self.lbl.setPixmap(QPixmap(":/img/background.png").scaled(self.width(), self.height(), Qt.KeepAspectRatio, transformMode=Qt.SmoothTransformation)) 

for example, I show only the first 2 lines, then they are repeated 12 times, respectively, this is exactly what slows down the resize. Is it possible to somehow stretch the image to fit the window? Also at the end, the onActivated() function is onActivated() which checks the state of the checkbox and does its job:

 def onActivated(self): if self.check1.isChecked(): self.lbl1.show() else: self.lbl1.hide() 

The same piece of code is repeated 12 times, under each label.

    1 answer 1

    I did not work with pyqt, but for general reasons there is an assumption that this line

     self.lbl.setPixmap(QPixmap(":/img/background.png").scaled(self.width(), self.height(), Qt.KeepAspectRatio, transformMode=Qt.SmoothTransformation)) 

    will load the file /img/background.png from the disk each time and this will be the most problematic part of the process, since reading from the disk is much slower than reading from the RAM

    Try to read the file only once - before you draw this element for the first time and save it to the attribute:

     self.pixmap = QPixmap(":/img/background.png") 

    and then with each resize, do this:

     self.lbl.setPixmap(self.pixmap.scaled(self.width(), self.height(), Qt.KeepAspectRatio, transformMode=Qt.SmoothTransformation)) 
    • Yes, indeed, the most obvious option missed, it became easier, but still there is some delay insignificant, I will think how to wrap all the images in one label or something, I think it will help - Samar