Answer the question
In order to leave comments, you need to log in
Why are widgets stacked on top of each other?
CocomoWidget::CocomoWidget(QWidget* parent) : QWidget(parent) {
auto scaleLabel = new QLabel("Размер проекта:", this);
auto scaleSpinBox = new QSpinBox(this);
scaleSpinBox->setRange(1, 1000000);
scaleSpinBox->setSingleStep(10);
scaleSpinBox->setValue(10);
scaleSpinBox->setSuffix(" KLOC");
auto scaleLayout = new QHBoxLayout(this);
scaleLayout->addWidget(scaleLabel);
scaleLayout->addWidget(scaleSpinBox);
auto topLayout = new QVBoxLayout(this);
topLayout->addLayout(scaleLayout);
this->setLayout(topLayout);
}
Answer the question
In order to leave comments, you need to log in
That's how it works. Look at the application console, it probably wrote "QLayout: Attempting to add QLayout "" to CustomWidget "", which already has a layout", because it was set when you specified this as a constructor parameter.
auto scaleLabel = new QLabel("Размер проекта:", this);
auto scaleSpinBox = new QSpinBox(this);
scaleSpinBox->setRange(1, 1000000);
scaleSpinBox->setSingleStep(10);
scaleSpinBox->setValue(10);
scaleSpinBox->setSuffix(" KLOC");
auto scaleLayout = new QHBoxLayout;
scaleLayout->addWidget(scaleLabel);
scaleLayout->addWidget(scaleSpinBox);
auto topLayout = new QVBoxLayout;
topLayout->addLayout(scaleLayout);
this->setLayout(topLayout);
You only need one empty Layout in which to shove the rest of the Layout.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question