#include #include #include #include #include #include #include #include #include #include QWidget* crearControl(int i, int j) { static int tipo = rand() % 5; switch ( tipo ) { case 0: return new QLabel( QString("Label (%1, %2)").arg(i + 1).arg(j + 1)); case 1: return new QLineEdit( QString("LineEdit (%1, %2)").arg(i + 1).arg(j + 1)); case 2: return new QTextEdit( QString("TextEdit (%1, %2)").arg(i + 1).arg(j + 1)); case 3: return new QCheckBox( QString("Checkbox (%1, %2)").arg(i + 1).arg(j + 1)); case 4: return new QRadioButton( QString("RadioButton (%1, %2)").arg(i + 1).arg(j + 1)); } return 0; } int main(int argc, char* argv[]) { srand( time(0) ); QApplication app(argc, argv); QWidget mainWindow; QVBoxLayout* mainLayout = new QVBoxLayout(&mainWindow); QGridLayout* gridLayout = new QGridLayout(); mainLayout->addLayout( gridLayout ); for ( int i = 0; i < 5; ++i ) for ( int j = 0; j < 4; ++j ) gridLayout->addWidget( crearControl(i,j), i, j ); QPushButton* botonSalir = new QPushButton("Salir"); mainLayout->addWidget( botonSalir ); QObject::connect( botonSalir, SIGNAL(clicked()), &mainWindow, SLOT(close()) ); mainWindow.show(); return app.exec(); }