Maintain a Square aspect ratio on widget resizing
-
Hello I have a 1920x1080 window with a frame inside that had 10 qlabels. 50x50 size each
I want to be able to resize my 1920x1080 window to anything and still be able to maintain the square ratio
i have tried working with heightforwidth() but i dont think it works on windows+latest versions
-
@DannyL408 said in Maintain a Square aspect ratio on widget resizing:
i have tried working with heightforwidth() but i dont think it works on windows+latest versions
did you set a custom size policy with height-for-width enabled?
QSizePolicy p = this->sizePolicy(); p.setHeightForWidth( true ); this->setSizePolicy( p );
-
yes i did,
i did some print statements to see if heightforwidth was being called and it wasntI have an inherited QLabel in the constructor
QSizePolicy qsp(QSizePolicy::Preferred,QSizePolicy::Preferred); qsp.setHeightForWidth(true); setSizePolicy(qsp);
QSize custom::sizeHint() const{
qDebug() << "called";
return QSize(25,25);
}
int custom::heightForWidth ( int w ) const{
qDebug() << this->size() << w;
return w;
}problem is they will just take up all the available space and wont be a perfect square on every resolution
-
@DannyL408
play around with the size policy values.QSizePolicy::Preferred
is the most general one and actually lets the layout almost do what it wants. -
@raven-worx said in Maintain a Square aspect ratio on widget resizing:
play around with the size policy values. QSizePolicy::Preferred is the most general one and actually lets the layout almost do what it wants.
none of the sizepolicies seem to work to keep the widget a perfect square on every resolution