Display image in Qt to fit label size

前端 未结 7 1196
[愿得一人]
[愿得一人] 2021-02-01 02:53

I already tried several methods on displaying an image on a form, but none of them works how I would like.

I\'ve read many places that the easiest way is to create a la

7条回答
  •  迷失自我
    2021-02-01 03:28

    ui->label->setPixmap( pix.scaled( ui->label->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation) );

    Worked like charm for my case (Qt 5.11). pix is a QPixmap object with the original pixel count (e.g. constructed with QPixmap::fromImage(path)).

提交回复
热议问题