#includeint main(int argc, char *argv[]) { QApplication app(argc, argv); QWidget *contentArea = new QWidget(); QVBoxLayout *layout = new QVBoxLayout(); QLabel *label1 = new QLabel("Some text here..."); QLabel *label2 = new QLabel("More text here..."); layout->addWidget(label1); layout->addWidget(label2); contentArea->setLayout(layout); QScrollArea *scrollArea = new QScrollArea(); scrollArea->setWidget(contentArea); scrollArea->show(); return app.exec(); }
#includeThis example creates a QScrollArea widget and sets its content to a widget containing a vertical layout that holds 20 QLabel widgets with sequential text. Additionally, it sets the widget resizable to allow scrolling of the content area. The example demonstrates how to set the widgetResizable to true using the setWidgetResizable method. Package/Library: Qt Widgetsint main(int argc, char *argv[]) { QApplication app(argc, argv); QWidget *contentArea = new QWidget(); QVBoxLayout *layout = new QVBoxLayout(); for(int i = 0; i < 20; i++) { QLabel *label = new QLabel(QString("Label %1").arg(i)); layout->addWidget(label); } contentArea->setLayout(layout); QScrollArea *scrollArea = new QScrollArea(); scrollArea->setWidgetResizable(true); scrollArea->setWidget(contentArea); scrollArea->show(); return app.exec(); }