Qt图片显示
1.图片截取指定大小
void Setting_TabProduct::changeImageSize(int width,int height,QString imgFile) { QPixmap pixmap(imgFile); if(width==pixmap.width()&&height==pixmap.height()){ }else{ QPixmap img=pixmap.scaled(width,height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); img.save(imgFile); } }
2.图片在QLabel自动适应大小显示
void MainWindow::ShowCarPic() { QPixmap pixCar; pixCar.load(":/images/car.png"); pixCar.scaled(ui->lblPicCar->size(),Qt::KeepAspectRatio); ui->lblPicCar->setScaledContents(true); ui->lblPicCar->setPixmap(pixCar); }