You want the QScrollArea to abandon its reason for existing and grow to accomodate its content. That is precisely what it is designed not to do. The scroll area gets the space allocated to it by its parent layout/widget and allows you to display an arbitrary sized widget within that space, using scrollbars as needed.

To defeat the default behaviour you have to do the work. When the contentsWidget() changes size you must manually change (force) the horizontal dimension of the QScrollArea to accomodate the contained widget's width plus a margin and width for a vertical scroll bar if one is present.