QApplication a(argc, argv); MainWindow w; QHBoxLayout*lay1=new QHBoxLayout; QHBoxLayout*lay2=new QHBoxLayout; QVBoxLayout*lay3=new QVBoxLayout; QLineEdit*edit1=new QLineEdit; QLineEdit*edit2=new QLineEdit; QLineEdit*edit3=new QLineEdit; QLineEdit*edit4=new QLineEdit; w.setLayout(lay3); lay3->addLayout(lay1); lay3->addLayout(lay2); lay1->addWidget(edit1); lay1->addWidget(edit2); lay2->addWidget(edit3); lay2->addWidget(edit4); edit1->show(); edit2->show(); edit3->show(); edit4->show(); w.show(); return a.exec();
C++ (Qt)QLineEdit*edit1=new QLineEdit( &w );
C++ (Qt)#include <QApplication>#include <QMainWindow>#include <QLineEdit>#include <QVBoxLayout>#include <QDebug> int main( int argc, char *argv[] ){ QApplication app( argc, argv ); QMainWindow w; qDebug() << "w = " << &w; QVBoxLayout *layout = new QVBoxLayout; QLineEdit *edit = new QLineEdit; layout->addWidget( edit ); qDebug() << "Parent edit = " << edit->parent(); w.setLayout( layout ); qDebug() << "Parent edit = " << edit->parent(); w.show(); return app.exec();}