I'm trying to implement a scalable image widget with qt creator that will preserve the aspect ratio of the image. All the examples or posts I've found suggest extending QLabel and reimplementing resizeEvent. This is what I've done and it almost works, but for a few problems.
When the main window first opens the images grow slightly and expand the size of the main window (this is not too big a problem).
When I maximize the window all the images scale up, but when I unmaximize the window the images fail to scale back down.
I have tried changing the resizeEvents of both the QLabel subclass (called ClickableImage) and the parent widget that holds the layout containing the ClickableImage. Here is some of the relevant code.
void ClickableImage::resizeEvent(QResizeEvent *e)
{
qDebug() << "Resizing : " << ticker;
ticker++;
int w = e->size().width();
int h = e->size().height();
qDebug() << "W : " << w;
qDebug() << "H : " << h;
image = QPixmap(fname);
image = image.scaled(w-7, h-7, Qt::KeepAspectRatio);
setPixmap(image);
}
Also, I've read the following sources,
Qt: resizing a QLabel containing a QPixmap while keeping its aspect ratio
https://docs.huihoo.com/qt/4.2/desktop-screenshot.html
Thanks.