Important: Please read the Qt Code of Conduct -

Resizing problems with widgets

  • Hello All,

    I'm having some problems with widget resizing in my app. I have a QScrollArea and a QWidget with a QVBoxLayout. I am adding multiple QLabel widgets with pixmaps to the layout. The problem is when I resize the QScrollArea, all of the other widgets including the pixmaps are being resized. When I resize the labels and update the QVBoxLayout, everything gets resized to fit the QScrollArea. The behavior I need is for the QScrollArea to adjust it's scrollbars to fit the children and for the QVBoxLayout to layout based on the child widgets size instead of the QScrollArea size. I hope that makes sense. I've been digging through the docs, but I guess I may be missing something in understanding how sizing works. I could really use some advice on this. Could one of y'all point me in the right direction?


  • I had the same problem some times ago. You have to make the QScrollArea get only one widget.

    Here's the whole method I used :

    -Put all you need in a general layout
    -Set the parent of that layout as a general widget
    -Use void QScrollArea::setWidget ( QWidget * widget )

    The behaviour of the scroll area should be allright

  • Hi,

    Thanks for your help! I think I am already doing this. Here my code (the latest version anyway):



    vlayout = new QVBoxLayout();

    scrollArea = new QScrollArea;

    baseWidget = new QWidget(scrollArea);
    baseWidget->setMaximumSize(2000, 11000);




    for (index = 1; index <= pagecnt; index++)


    QImage image((const uchar *)bits, hdr.width, hdr.height, QImage::Format_RGB888);

    QLabel *label = new QLabel(baseWidget);



    Everything displays correctly initially. When I resize the main window, the children of the scroll area resize. When I resize the labels, the scroll area's scroll bars do not update to the new size. If I resize the labels and then change the main window size, the labels are resized to the scroll area size. Is there something that I'm missing?


  • Hello All,

    I figured this out. I need to call label->setMinimumSize and label->setMaximumSize.


Log in to reply