C++ (Qt)QLabel *imageLabel = new QLabel; QImage image("happyguy.png"); imageLabel->setPixmap(QPixmap::fromImage(image)); scrollArea = new QScrollArea; scrollArea->setBackgroundRole(QPalette::Dark); scrollArea->setWidget(imageLabel);
C++ (Qt)WindowData::WindowData():QScrollArea(){ QWidget* base = new QWidget( this ); setWidget( base ); GridLayout = new QGridLayout( base ); setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); GridLayout->setAlignment(Qt::AlignTop); QLabel *QuantityLabel, *LengthLabel, *WidthLabel; // ... GridLayout->addWidget(QuantityLabel,0,0); GridLayout->addWidget(QuantityField,0,1); GridLayout->addWidget(LengthLabel,1,0);}
C++ (Qt)#include <QApplication>#include <QScrollArea>#include <QLabel>#include <QLineEdit>#include <QGridLayout> int main( int argc, char* argv[] ){ QApplication app( argc, argv ); QScrollArea sa; QWidget base( &sa ); sa.setWidget( &base ); QGridLayout l( &base ); for( int i = 0; i < 100; i++ ) { l.addWidget( new QLabel( QString( "%1:" ).arg( i + 1 ) ), i, 0, Qt::AlignRight ); l.addWidget( new QLineEdit(), i, 1, 1, 20 ); } #if 1 // сам выбирай, что тебе больше нравится sa.setWidgetResizable( true );#else base.adjustSize();#endif sa.show(); return app.exec();}
QWidget base( &sa ); sa.setWidget( &base );