I have a QLabel with a sizepolicy of QSizePolicy::Expanding in both dimensions in which I want to show an image with QLabel::setPixmap. The mainwindow should not be resized, that's why I scale the pixmap before setting to the size of the QLabel.
The image is set correctly, but on top and on bottom there is a padding I don't want, on top 12px, bottom 13px. The setPixmap-command resizes the QLabel and the mainwindow. I can't figure out why. The stylesheet of the QLabel is empty. I can color the QLabel-background to see that the extra space is a padding of the QLabel (or margin of the pixmap). When I try to resize the mainwindow, I can't get it so small that this extra border disappears, I can enlarge it and the padding increases on all sides (like expected), but I can't get it smaller to get rid of this extra margin.
Does anybody know what could cause this?
EDIT:
added some code.
Before these lines ui->label_title is empty and label_title is in the same vertical layout just on top of label_main. I just thought, that when some text is set to label_title, the layout is not yet updated, so the next line returns the old size and then the image is too big, because the title took some space and the mainwindow has to be resized. Is there a command to update the layout, so all widgets in it get their new size? layout->update(); did'nt work.
ui->label_title->setText(imgNames.at(crntItemNr));
QSize size = ui->label_main->size();
ui->label_main->setPixmap(images.at(crntItemNr).scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation));