How is it possible to maintain widgets aspect ratio in Qt and what about centering the widget?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You don’t have to implement your own layout manager. You can do with inheriting
QWidgetand reimplementingto stay square. However,
heightForWidth()doesn’t work on toplevel windows on X11, since apparently the X11 protocol doesn’t support that. As for centering, you can passQt::AlignCenteras the third parameter ofQBoxLayout::addWidget()or the fifth parameter ofQGridLayout::addWidget().Note: In newer versions of Qt at least, QWidget does not have the
heightForWidthorwidthForHeightanymore (so they cannot be overriden), and thereforesetWidthForHeight(true)orsetHeightForWidth(true)only have an effect for descendants of QGraphicsLayout.