Unsolved Qt5 - CPP - How to resize a QScrollList
-
I have the following problem.
I have scroll list of widgets which is looking like this (if it's expended on X way too much)
If I will scale it on Y-axis it's going to look like this.
I'm trying to make those blue widgets to keep their aspect ratio, doesn't matter the size of the container. In order to do that I've reimplemented the
resizeEvent
like this:void PolygonButtonWidget::resizeEvent(QResizeEvent *event) { auto ratioW = 8; auto ratioH = 3; float thisAspectRatio = (float) event->size().width() / event->size().height(); if (thisAspectRatio < ratioW / ratioH) { auto w = event->size().height() * ratioW / ratioH; auto h = event->size().height(); qDebug() << hasHeightForWidth() << " " << w << " " << h; this->resize(w, h); if (m_nrButtons != 0) { this->move((w + 20) * m_nrButtons, this->y()); } } QWidget::resizeEvent(event); }
By doing this my list is going to look something like this
or like this
How can I fix this? For some reason, some of my widgets are going to disappear, what should be my approach in order to fix this issue?
-
@Vildnex said in Qt5 - CPP - How to resize a QScrollList:
I don't know about the answer you are seeking, but while you are waiting for someone else to answer:auto ratioW = 8; auto ratioH = 3; float thisAspectRatio = (float) event->size().width() / event->size().height(); if (thisAspectRatio < ratioW / ratioH) {
That
ratioW / ratioH
looks like an integer division to me?