6

I have a ui with a QScrollArea Widget. The QScrollArea uses a Flowlayout. My problem is when I add widgets to my layout the scroll area begins to scroll and does not expand when it has room to expand. I want the scroll area to expand to its limit before the scroll bar appears first.

How can I get the scroll area to expand before the scroll bar appears?

andre
  • 7,018
  • 4
  • 43
  • 75

2 Answers2

7

can you try doing setWidgetResizable(true) for your QScrollArea

ScrollArea->setWidgetResizable(true);
cbuchart
  • 10,847
  • 9
  • 53
  • 93
Vinod Paul
  • 359
  • 2
  • 14
0

A couple of suggestions:

  1. Ensure that the size policy of the scroll area itself is Expanding.
  2. Set the "stretch" values of the size policy of the scroll area to a value greater than that of the other widgets in the same layout. Ie:

    QSizePolicy policy = pScrollArea->sizePolicy()
    
    policy.setVerticalStretch(1);
    policy.setHorizontalStretch(1);
    

    This assumes that the siblings of the scroll area (if any) have a stretch value of 0 (the default).

  3. Subclass the scroll area and override the sizeHint() method.

piccy
  • 336
  • 2
  • 12