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技术)