Results 1 to 3 of 3

Thread: Qt - C++ - ScrollArea - Resize content widgets by keeping the aspect ratio

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2020
    Qt products
    Unix/X11 Windows

    Default Qt - C++ - ScrollArea - Resize content widgets by keeping the aspect ratio

    I'm new to Qt and I've encountered the following problem.

    I have a layout that looks like this.


    Blue: rectangle it's a ScrollArea

    Orange: rectangles are the widgets from that ScrollArea



    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.


    • 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:

    Qt Code:
    1. ui->setupUi(this);
    3. ui->scrollArea->setWidgetResizable(true);
    5. for (auto i = 0; i < 10; ++i) {
    6. auto *targetWidget = new PolygonButtonWidget();//let it be target object
    7. ui->scrollAreaWidgetContents->layout()->addWidget(targetWidget);
    8. }
    9. 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?
    Attached Images Attached Images

Similar Threads

  1. Replies: 3
    Last Post: 2nd September 2016, 12:44
  2. Replies: 3
    Last Post: 26th May 2015, 23:14
  3. Replies: 2
    Last Post: 7th December 2013, 19:02
  4. Replies: 0
    Last Post: 21st November 2011, 07:55
  5. keeping aspect ratio while resizing
    By franco.amato in forum Qt Programming
    Replies: 2
    Last Post: 19th November 2009, 20:12

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.