Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

No scrolling in ScrollArea



  • Hello everyone,
    I have implemented a QScrollArea into a widget. However, When I add multiple data into the scroll area, it just shrivels the data together and doesn't allow for the scroll functionality. Here is the code the code I have used:

    
            while(query->next())
            {
                QString title = query->value(0).toString();
                qDebug() << title;
                titles.push_back(title);
    
                QString link = query->value(1).toString();
                qDebug() << link;
                links.push_back(link);
    
                QString image = query->value(2).toString();
                qDebug() << image;
                images.push_back(image);
            }
    
    
        } else{
            qDebug() << "Couldn't connect";
        }
    
        QScrollArea *scrollArea = new QScrollArea(this);
        QVBoxLayout *layout = new QVBoxLayout;
    
        ui->mainWidget->setLayout(layout);
        layout->addWidget(scrollArea);
    
        QVBoxLayout *scrollLayout = new QVBoxLayout;
        scrollArea->setLayout(scrollLayout);
    
        for(int i=0; i<10; ++i){
            QWidget *tempWidget = new QWidget;
            QHBoxLayout *tempLayout = new QHBoxLayout;
    
            tempWidget->setLayout(tempLayout);
            QLabel *label = new QLabel("Test");
    
            tempLayout->addWidget(label);
            scrollLayout->addWidget(tempWidget);
        }
    
    

  • Lifetime Qt Champion

    Hi,

    Because you are doing it wrongly. Your scrollLayout should be applied to a widget that you set on the QScrollArea.


Log in to reply