How to create a Grid Layout, containing images and labels, as Widget Layout of Vertical Scrollable Area



  • Hi everyone.

    I'm new of Qt and I just started to make the GUI of my project but I'm stuck on the Scroll Area part.

    Since the concept of what I'd like to do is a bit complicated I did sketched it with paint (with my awesome paint skills!!):

    0_1547157521979_explaination.png

    To achieve this result I managed to create the Scroll Area in this way:

    @

    QScrollArea*SA = new QScrollArea(this);
    SA ->setGeometry(100,64,352,250);
    SA ->verticalScrollBar()->setStyleSheet("QScrollBar {height:0px;}");
    
    QVBoxLayout* VBL = new QVBoxLayout;
    VBL ->setMargin(0);
    VBL ->setSpacing(0);
    
    QWidget* containerWidget = new QWidget;
    containerWidget->setLayout(VBL);
    SA ->setWidget(containerWidget);
    

    @

    I'm stuck at this point. At the moment some QPushButtons were added (VBL->setWidget(QPushButton);) to test if everything was working fine and it does, but the widget I'd like to add is the whole Object of the Scrollable Area shown in the picture.

    Does anyone have any idea about how to create this?

    Thank you in advance!


  • Qt Champions 2018

    @cppStudent012 I'm not sure what the problem is. For each of these objects inside the scrollable area you can simply insert a widget (and add this widget to the layout) and on this widget you put all the elements (don't forget to add a layout to this widget).
    So:

    QScrollarea:
        QWidget:
            QVBoxLayout:
                QWidget:
                    Q*Layout (check which layout is the proper one for your use case):
                        picture
                        ...
    


  • @jsulm Thank you for answering!

    I didn't understand that every single Layout object had to be wrapped in a QWidget one.

    Everything works fine in the way you said!

    Thank you very much!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.