I am currently working on a Qt project for my school. For this project I need to list an unknown number of elements in a window without resizing its content.
I've used some VBoxLayout in the past, but it isn't what I am searching at all. This widget resizes its content depending on the number of elements it contains. What I would like is to add as much widgets as I need into the "scrolling widget", which will stack next to each other automatically and won't resize.
I tried using QScrollArea but I wasn't able to make elements stack on each others.
Here is a small drawing explaining my problem:

Here is how I do it with a QVBoxLayout and a QScrollArea:
//scrollview so all items fit in window
    QScrollArea* techScroll = new QScrollArea(tabWidget);
    techScroll->setBackgroundRole(QPalette::Window);
    techScroll->setFrameShadow(QFrame::Plain);
    techScroll->setFrameShape(QFrame::NoFrame);
    techScroll->setWidgetResizable(true);
    //vertical box that contains all the checkboxes for the filters 
    QWidget* techArea = new QWidget(tabWidget);
    techArea->setObjectName("techarea");
    techArea->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
    techArea->setLayout(new QVBoxLayout(techArea));
    techScroll->setWidget(techArea);
Then when adding items you do it like this (with lay = techArea->layout() and parent = techarea:
for(std::set<Event::Enum>::iterator it = validEvents.begin(); it != validEvents.end();
    ++it){
        QCheckBox* chk = new QCheckBox(
        "text", parent);
        if(lay){
            lay->addWidget(chk);
        }   
    }
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With