Qt图片适应QLabel大小

   

    QImage Image;
    Image.load("d:/test.jpg");
    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);

 

你可能感兴趣的:(QT)