I can’t get the widget to keep its aspect ratio

I am making a program with Qtcreator (using a qt designer too). I made some QSvgWidget buttons (what I wanted was a button with a scalable image). They work, but do not preserve the aspect ratio of the image (aspect ratio should be 1: 1). I could not come up with a solution for this myself, even after several hours of trying.

I tried:

QSizePolicy qsp(QSizePolicy::Preferred,QSizePolicy::Preferred);
qsp.setHeightForWidth(true);
ui->Widgetname->setSizePolicy(qsp);

But that does not work.

Some images of the problem:


Correctly:

enter image description here

Wrong:

enter image description here enter image description here


I am new to Qt and coding.

What am I doing wrong?

+4
source share

All Articles