QT实现滚动条

时间:2024-10-08 07:14:42
void Form::initForm() { QHBoxLayout *layout=new QHBoxLayout(); QHBoxLayout *layoutMain=new QHBoxLayout(); QScrollArea *scrollArea=new QScrollArea(); for(int i=0;i<15;i++) { QLabel *label=new QLabel(); label->setText(QString("Test%1").arg(1)); layout->addWidget(label); } ui->widget1->setLayout(layout); scrollArea->setWidget(ui->widget1); scrollArea->setWidgetResizable(true); layoutMain->addWidget(scrollArea); ui->widget->setLayout(layoutMain); }