PDA

View Full Version : MainWindow::resizeEvent - Infinite Cycle



metRo_
1st June 2010, 16:51
Hi,
I want to change the image size according to mainwindow size but it's go in a infinite cycle and after start stills increment the size.

#include "mainwindow.h"
#include <QtGui>

MainWindow::MainWindow(QWidget *parent) :
QWidget(parent)
{
QHBoxLayout *lay=new QHBoxLayout;
setLayout(lay);
image=new QImage("comando.jpg");
imageLabel = new QLabel(this);
lay->addWidget(imageLabel);
imageLabel->setPixmap(QPixmap::fromImage(image->scaled(400,400,Qt::KeepAspectRatio)));
}

MainWindow::~MainWindow()
{

}

void MainWindow::resizeEvent (QResizeEvent * event )
{
imageLabel->setPixmap(QPixmap::fromImage(image->scaled(size(),Qt::KeepAspectRatio)));
}

Lykurg
1st June 2010, 17:04
See scaled content for QLabel then you don't need the resize event.

EDIT: and why it is getting bigger and bigger is probably that your label has an extra margin around the image.

metRo_
2nd June 2010, 00:33
I already saw it but i can make it work that way :S Can you gime some more information?

How can i edit the margin?