QGroupBox, QScrollArea, QFormLayout
-
Widget.h
#include <QWidget> class QScrollArea; class QFormLayout; class Widget : public QWidget { Q_OBJECT public: explicit Widget(QWidget *parent = nullptr); private: void showEvent(QShowEvent* event); QScrollArea* pScrollArea; QFormLayout* pFormLayout; };
Widget.cpp
Widget::Widget(QWidget *parent) : QWidget(parent) { auto vLayout=new QVBoxLayout; setLayout(vLayout); pScrollArea=new QScrollArea; vLayout->addWidget(pScrollArea); auto sWidget=new QWidget; pScrollArea->setWidget(sWidget); pScrollArea->setWidgetResizable(true); pFormLayout=new QFormLayout; pFormLayout->setContentsMargins(0,0,0,1); pFormLayout->setSpacing(0); pFormLayout->setHorizontalSpacing(10); sWidget->setLayout(pFormLayout); // add one row for calculation in showEvent pFormLayout->addRow("", new QLabel()); vLayout->addWidget(new QPushButton("Clear")); }
@mpergand , Thank you, works a treat...now to port to my main application:
ui->setupUi(this); QVBoxLayout* pvbxLayout(new QVBoxLayout); mpsa = new QScrollArea; pvbxLayout->addWidget(mpsa); QWidget* pContainer(new QWidget); mpsa->setWidget(pContainer); int intFixedHeight(fontMetrics().height() * 3); mpsa->setFixedHeight(intFixedHeight); mpsa->setWidgetResizable(true); mpFormLayout = new QFormLayout; mpFormLayout->setContentsMargins(0,0,0,0); mpFormLayout->setSpacing(0); mpFormLayout->setHorizontalSpacing(10); pContainer->setLayout(mpFormLayout); for( int i=1; i<=10; i++ ) { mpFormLayout->addRow(QString::number(i), new QLabel(QString("Hello World: %1").arg(i))); } pvbxLayout->addWidget(new QPushButton("HELLO")); ui->centralwidget->setLayout(pvbxLayout);