Important: Please read the Qt Code of Conduct -

Fit image into Qlabel

  • Hello dear programmers.
    Well as the subject says i want to Fit my image in Qlabel but here is the case,
    there is scaleContent for that Qlabel that does the Opposite job of fitting an image.
    it stretches the image in both vertical and horizontal.
    so any idea of how to do the trick?
    i used Pixmap not QPicture:

    QPixmap image(":/new/prefix1/background/main logo_.png");
    [Example of fitting an image](
    ```![alt text](image url)

  • Lifetime Qt Champion


    Since you can get the size of the label, you can use QPixmap::scaled to resize the image.

  • Hi! If I got it right you should use this.

    For example:

    const int w = label->width();
    const int h = label->height();

  • @Suares

    Final eddit ,KeepAspectRatio was the aspect ratio mode that needed for Fitting an image into Qlabel

    QPixmap image("image address");

Log in to reply