Hello, I've been reading about what I'm gonna ask, but I didn't find a solution.
I have a QImage on a QLabel, and I want to resize that image (and the QLabel, of course) when the window of my App is resized, all I have read is that I have to use layouts, but I don't understand how, cause the adjustSize() layout only changes the position of my label and what I want is to change it label->width() and label->height().
I have a little code that override the virtual method resizeEvent:
QSize oldSize
= event
->oldSize
();
QSize actualSize
= event
->size
();
if(ui->label->isVisible()){
double width = actualSize.width() / (double)oldSize.width(),
height = actualSize.height() / (double)oldSize.height();
ui->label->resize(ui->label->size().width() * width,
ui->label->size().height() * height);
showImage(actualImage);
}
}
void MainWindow::resizeEvent(QResizeEvent *event){
QSize oldSize = event->oldSize();
QSize actualSize = event->size();
if(ui->label->isVisible()){
double width = actualSize.width() / (double)oldSize.width(),
height = actualSize.height() / (double)oldSize.height();
ui->label->resize(ui->label->size().width() * width,
ui->label->size().height() * height);
showImage(actualImage);
}
}
To copy to clipboard, switch view to plain text mode
but it doesn't work properly, it resizes the photo, but when I resize the window many times, the label is getting smaller each time until it disappears. I'm pretty sure that the problem here is about the int var, because it loses information each time I resize.
Which is the best way to do what I want?
Thanks!
Bookmarks