代码示例:
自定义显示图片大小和位置*/
/*QPixmap pix = QPixmap(fileName);
pix = pix.scaled(QSize(236, 236), Qt::KeepAspectRatio); //调整图片大小
ui.label_pix->setAlignment(Qt::AlignCenter); //居中显示
ui.label_pix->setPixmap(pix);
/*图片自适应label大小*/
QPixmap pix = QPixmap(fileName);
pix = pix.scaled(ui.label_pix->size(), Qt::KeepAspectRatio); //图片大小为label大小
ui.label_pix->setScaledContents(true); //子控件显示填充整个label
ui.label_pix->setPixmap(pix);