Qt scrollArea not scrolling content
Solved
General and Desktop
-
So i added the scrollArea in the QtDesigner named scrollAreaPalettes
Then i populate the scrollArea in code with buttonsQVBoxLayout *vlayout = new QVBoxLayout; ui->scrollAreaPalettes->setLayout(vlayout); for (auto v : value) { QString paletteName = v.toObject().value("Name").toString(); QString paletteImage = v.toObject().value("imageURL").toString(); QJsonArray palettePalette = v.toObject().value("palette").toArray(); QPushButton *button = new QPushButton; button->setObjectName(paletteName); button->setText(paletteName); button->setCursor(Qt::PointingHandCursor); button->setMinimumHeight(46); button->setMaximumHeight(46); button->setStyleSheet("border-image: url("+paletteImage+") 0 0 0 0 stretch stretch;margin-right:17px;margin-bottom:17px;"); connect(button, &QPushButton::clicked, [=]() { socket.sendBinary("paletteNew", palettePalette); qDebug() << "Palette Data Size : " << palettePalette.size(); }); vlayout->addWidget(button); }
But no matter how many elements i add the scrollbar never activates it just keeps squishing the elements down to fit in the scrollArea window :S
-
got it working by some intense gooooooogling
Entire code:
QWidget *widget = new QWidget(); QVBoxLayout *vlayout = new QVBoxLayout(widget); ui->scrollAreaPalettes->setWidget(widget); for (auto v : value) { QString paletteName = v.toObject().value("Name").toString(); QString paletteImage = v.toObject().value("imageURL").toString(); QJsonArray palettePalette = v.toObject().value("palette").toArray(); QPushButton *button = new QPushButton; button->setObjectName(paletteName); button->setText(paletteName); button->setCursor(Qt::PointingHandCursor); button->setMinimumHeight(46); button->setMaximumHeight(46); button->setStyleSheet("border-image: url("+paletteImage+") 0 0 0 0 stretch stretch;margin-right:17px;margin-bottom:17px;"); connect(button, &QPushButton::clicked, [=]() { socket.sendBinary("paletteNew", palettePalette); qDebug() << "Palette Data Size : " << palettePalette.size(); }); vlayout->addWidget(button); }
Changes:
// Added QWidget *widget = new QWidget(); // Changed QVBoxLayout *vlayout = new QVBoxLayout; // To QVBoxLayout *vlayout = new QVBoxLayout(widget); //Changed ui->scrollAreaPalettes->setLayout(vlayout); // To ui->scrollAreaPalettes->setWidget(widget);