Important: Please read the Qt Code of Conduct -

Adjust an SVG image to qlabel

  • Hello,

    I have created my application, I created a label that should show an SVG image from a file, so far, I have been able to make it to show the image, but it is neither centered nor size adjusted, I tried the following code but it did nothing:

        QPixmap pix("imagelocation.svg");   
        int w = ui->label_pic->width();
        int h = ui->label_pic->height();

    Can someone help me please?

    Thank you!

  • Lifetime Qt Champion


    When and where are you calling that code ?

  • Im calling the code after creating this img by pressing a button, another problem Im facing iz that when I press the button I cant see changes till I drag (expand) the window borders, could this has something to do?

    Thank you!

  • Lifetime Qt Champion

    You need to provide a bit more context. A minimal compilable example would be best with also a sample svg file that triggers this.

    By the way, which version of Qt are you using ? On what platform ?

Log in to reply