[PyQt] Resizing QLabel

F.A.Pinkse fapinkse at gmail.com
Fri Aug 19 16:41:35 BST 2011


Hi All,

In Order to resize my images and keeping their aspect I did subclass 
Qlabel Like this as found suggested elsewhere on the net:

from PyQt4.QtCore import *
from PyQt4.QtGui import *

class MyLabel(QLabel):
     def __init__(self, parent=None):
         super(MyLabel, self).__init__(parent)
         self.orgPixmap=None

     def resizeEvent(self,  event):
         if self.orgPixmap != None:
             pixmap = self.orgPixmap
             size = event.size()
             self.setPixmap(pixmap.scaledToHeight(size.height()-10))

             print('resize',  size.size())

It does what I want.. scaling my image when the label is resized all the 
way up to screen size and down to the appliztion minimal window size.

Now when I do a Maximize on my application window and back the resizing 
acts differently. I can see that the resizeEvent has been called
It does a few steps and stops when I release the mouse button I can do 
this afain abd again only a few steps at the time.

What is happenign here?

I am Using windows XP, Python 3, PyQt4

Thanks


Frans.




More information about the PyQt mailing list