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);
}

 

posted @ 2018-06-05 14:50  ike_li  阅读(278)  评论(0编辑  收藏  举报