위젯을 프로그래밍 방식으로 만들고 레이아웃을 통해 위치를 조정할 수 있습니다. 예를 들어, 지금과 같을 수 있습니다 당신이 재생할 수있는 레이아웃 (등 QBoxLayout, QGridLayout, QFormLayout)의 다른 종류가 있습니다
QVBoxLayout *topLayout = new QVBoxLayout();
for (int lineNumber = 0; lineNumber < 1024; ++lineNumber)
{
QWidget *oneLineWidget = new QWidget(this);
QHBoxLayout *oneLineWidgetLayout = new QHBoxLayout();
{ //added these brackets just for the ease of reading.
QLabel *labFirst = new QLabel(tr("first label"), oneLineWidget);
QLabel *labSecond = new QLabel(tr("second label"), oneLineWidget);
QPushButton *bFirst = new QPushButton(tr("first button"), oneLineWidget);
QPushButton *bSecond = new QPushButton(tr("second button"), oneLineWidget);
QRadioButton *rbFirst = new QRadioButton(tr("first radiobutton"), oneLineWidget);
QRadioButton *rbSecond = new QRadioButton(tr("second radiobutton"), oneLineWidget);
oneLineWidgetLayout->addWidget(labFirst);
oneLineWidgetLayout->addWidget(labSecond);
oneLineWidgetLayout->addWidget(bFirst);
oneLineWidgetLayout->addWidget(bSecond);
//lets put one radioButton under another.
QVBoxLayout *radioButtonsLayout = new QVBoxLayout();
{
radioButtonsLayout->addWidget(rbFirst);
radioButtonsLayout->addWidget(rbSecond);
}
//and now we can combine layouts.
oneLineWidgetLayout->addLayout(radioButtonsLayout);
}
oneLineWidget->setLayout(oneLineWidgetLayout);
topLayout->addWidget(oneLineWidget);
}
this->setLayout(topLayout);
. QLayout documentation부터 시작할 수 있습니다. 클래스를 상속하는 클래스 목록이 있습니다. 도움이되기를 바랍니다. :) 행운을 빕니다!
P. 나는 그것을 메모장에 썼고 "실생활에서"시험하지 않았다. 그래서 아마도 약간의 오류가 있습니다. 그러나 적어도 그것이 올바른 방향으로 당신을 가리킬 것이기를 바랍니다. – FreeNickname