View Full Version : Resizing a QLabel with a pimap. Won't shrink!

16th September 2010, 17:31
I'm using a QLabel to display images (I retreive the images from an SQLite database).

The label is part of a widget with a few other buttons and labels.

By using the QLabel::setScaledContents(true) (or the equivalent in Qt Designer). I can make it so the QLabel showing this image expands if the widget expands and the image displayed will expand accordingly.

But it won't resize smaller than the image's original size.

I can see why this behaviour might be desired in some cicumstances but it's not what I want.

I can work around the problem by setting the image in the QLabel to be a down-sized (scaled) image which gives me a smaller minimum size but then (obviously) the quality of the image is reduced if I expand it.

Any ideas?

17th September 2010, 12:39
A more advanced way to solve your problem can be create a subclass of QLabel and to reimplement the QWidget::resizeEvent method in way to use a down-sized version of pixmap when the qlabel becomes smaller than the pixmap.

17th September 2010, 18:30
Thanks for the reply,

Yeah, I realised that I could subclass the QLabel to make it work. It just seems like there might have been an easier way (not that it would be too hard to subclass it).