直接上代码:
- QImage Image;
- Image.load(<span style="font-family:Consolas, 'Courier New', Courier, mono, serif;line-height:18px;background-color:rgb(248,248,248);">"d:/test.jpg"</span>);
- QPixmap pixmap = QPixmap::fromImage(Image);
- int with = ui->labPic->width();
- int height = ui->labPic->height();
- QPixmap fitpixmap = pixmap.scaled(with, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); // 饱满填充
- //QPixmap fitpixmap = pixmap.scaled(with, height, Qt::KeepAspectRatio, Qt::SmoothTransformation); // 按比例缩放
- ui->labPic->setPixmap(fitpixmap);
|