QGridLayout *mainLayout = new QGridLayout; mainLayout->setContentsMargins(1, 1, 1, 1); element *test1 = new QLabel; element *test2 = new QLabel; element *test3 = new QLabel; element *test4 = new QLabel; QSpacerItem *spacer = new QSpacerItem(70, 100, QSizePolicy::Fixed); test1->setText("111"); test2->setText("222"); test3->setText("333"); test4->setText("444"); test1->setStyleSheet("background: white; border: 1px solid black;"); test2->setStyleSheet("background: red; border: 1px solid black;"); test3->setStyleSheet("background: blue; border: 1px solid black;"); test4->setStyleSheet("background: blue; border: 1px solid black;"); test1->setFixedSize(70, 100); test2->setFixedSize(70, 100); test3->setFixedSize(70, 100); test4->setFixedSize(70, 100); mainLayout->addWidget(test1, 0, 0, 0, 18); mainLayout->addItem(spacer, 0, 1, 0, 18); mainLayout->addWidget(test2, 0, 2, 0, 18); mainLayout->addWidget(test3, 1, 0, 2, 18); //mainLayout->addWidget(test4, 1, 1, 2, 18); setLayout(mainLayout);
QGridLayout *layout = new QGridLayout(this); QGridLayout *mainLayout = new QGridLayout(); QSpacerItem *horizontalSpacer = new QSpacerItem(geometry().width()-mainLayout->geometry().width(), 20, QSizePolicy::Expanding, QSizePolicy::Minimum); QSpacerItem *verticalSpacer = new QSpacerItem(20, geometry().height()-mainLayout->geometry().height(), QSizePolicy::Minimum, QSizePolicy::Expanding); element *test1 = new element(this); element *test2 = new element(this); element *test3 = new element(this); element *test4 = new element(this); test1->setText("111"); test2->setText("222"); test3->setText("333"); test4->setText("444"); mainLayout->addWidget(test1, 0, 0, 1, 1); mainLayout->addWidget(test2, 0, 1, 1, 1); mainLayout->addWidget(test3, 0, 2, 1, 1); mainLayout->addWidget(test4, 1, 2, 1, 1); layout->addLayout(mainLayout, 0, 0); layout->addItem(horizontalSpacer, 0, 1); layout->addItem(verticalSpacer, 1, 0);