Important: Please read the Qt Code of Conduct -

Why does this scrollable area not keep the wanted size of my images?

  • I have developed a Qt application. I built a form with Qt Designer. The important fact is that I have a Scroll Area like this :

    <widget class="QScrollArea" name="scrollArea">
    <property name="geometry">
    <property name="widgetResizable">
    <widget class="QWidget" name="scrollAreaWidgetContents">
     <property name="geometry">


    then, in my form, I first set a layout to my QscrollArea :

    Form::Form(QWidget *parent) :
    ui(new Ui::Form)
        gridLayout = new QGridLayout;

    then, I want to add 50 pictures and a progress bar for each picture (I am making multimedia retrieval actually) inside this ScrollArea

    for (int i=0;i<50;i++)
          QLabel * L = new QLabel;
          QProgressBar *dist=new QProgressBar;
          L->setGeometry(250,150, 100, 100);
          L->setObjectName("lab" + (i+1));
          dist->setObjectName("d" + (i+1));
          QString chemin ="my_path"+QString::fromStdString(im[i])+".jpg";
          QPixmap image(chemin);
          else if ((n_algo==2||n_algo==4)&&index_2==2)
          gridLayout->addWidget(L, 2*(i/10),i%10);

    But that gives sth like this :


    That's not so bad but it seems that the images are scaled in a way that all can be placed into the "physical" size of the area. Indeed, if I increase the number of columns (here the number of colums is 10, the denominator in the two last lines), I get the images are compressed (giving sth really odd) and it seems that the scroll bars are actually never useful (all is always stacked into a fixed size window).

    What I would like are images with a fixed, convenient size whatever the number of images to display or the disposition (number of rows and columns), where it would be able to scroll inside the scrollArea if needed to look at the pictures.

    Thanks for help !

  • Lifetime Qt Champion

    Since you are not setting a MinimumSize on the labels ( images ) i think the layout
    will just compress them - the more you images you add.
    You can try
    L->setMinimumSize(QSize(128,128)); // 128 is just random, not sure what you want.

Log in to reply