The easiest possible way is to let the label scale its contents:
SLD
::SLD(QWidget *parent, Qt
::WFlags flags
){
ui.setupUi(this);
label
->setPixmap
(QPixmap("Resources/CB.bmp"));
label->setScaledContents(true); // let the label scale its contents
setCentralWidget(label); // label will get automatically resized as a central widget
}
SLD::SLD(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
ui.setupUi(this);
QLabel* label=new QLabel(this);
label->setPixmap(QPixmap("Resources/CB.bmp"));
label->setScaledContents(true); // let the label scale its contents
setCentralWidget(label); // label will get automatically resized as a central widget
}
To copy to clipboard, switch view to plain text mode
If you need more intelligent scaling, like keeping aspect ratio or something, you might want to scale it by hand. This would be done by storing the image as a member variable, scaling it for example in resizeEvent() and setting the scaled image on the same label. I'd suggest doing it a bit delayed so that each and every resizeEvent() in a row doesn't scale and set a new image.
Notice that you were creating new QLabel widgets again and again during every resize event! Also, Qt has a concept of layouts to handle geometries. You barely set geometries by hand.
Bookmarks