I'm new to Qt and I've encountered the following problem.
I have a layout that looks like this.
Where:
Blue: rectangle it's a ScrollArea
Orange: rectangles are the widgets from that ScrollArea
345ZZ.png
----------
The problem arises when I'm trying to resize the window. In the moment of resizing, I want my widgets to keep their aspect ratio. But that's not going to happen.
Cases:
- If I will scale my application vertically my widgets are going to get way higher then they should. Instead, they should keep their current size because any vertical scaling will destroy they
- the same goes also for horizontal scaling
- at the same time if I will scale on horizontal and vertical at the same time I should get the same number of elements from that scroll area on the view. Doesn't matter the size of them
----------
Now my question arises... this resizing problem is caused by the scroll area or by the widget itself? How can I fix this?
----------
My code:
ui->setupUi(this);
ui->scrollArea->setWidgetResizable(true);
for (auto i = 0; i < 10; ++i) {
auto *targetWidget = new PolygonButtonWidget();//let it be target object
ui->scrollAreaWidgetContents->layout()->addWidget(targetWidget);
}
QScroller::grabGesture(ui->scrollArea, QScroller::LeftMouseButtonGesture);
ui->setupUi(this);
ui->scrollArea->setWidgetResizable(true);
for (auto i = 0; i < 10; ++i) {
auto *targetWidget = new PolygonButtonWidget();//let it be target object
ui->scrollAreaWidgetContents->layout()->addWidget(targetWidget);
}
QScroller::grabGesture(ui->scrollArea, QScroller::LeftMouseButtonGesture);
To copy to clipboard, switch view to plain text mode
Does anyone know how can I achieve my wanted result?
Bookmarks