我QGridLayout
内有QWidget
。我一直在为此添加子QGridLayouts
。我希望QWidget
根据子布局所需的大小调整大小,但是用户无法调整大小。
MainWindow.cpp(MainWindow
继承自QWidget
)
MainWindow::MainWindow(QWidget *parent) :
QWidget(parent)
{
QGridLayout *mainLayout = new QGridLayout();
{
AAController *ac1 = new AAController("Ins1");
AAController *ac2 = new AAController("Ins2");
AAController *ac3 = new AAController("Ins3");
mainLayout->addLayout(ac1, 0, 0);
mainLayout->addLayout(ac2, 0, 1);
mainLayout->addLayout(ac3, 1, 1);
}
setLayout(mainLayout);
}
AAController.cpp(AAController
继承自QGridLayout
)
AAController::AAController(const QString& instrument)
:_instrument(instrument)
{
_lblInstrument = new QLabel(_instrument);
_lblMismatchThreshold = new QLabel("Mismatch threshold : ");
_lblQuoteVolume = new QLabel("Quote volume : ");
_btnUpdateAlgo = new QPushButton("Update Algo");
_spnMismatchThreshold = new QSpinBox();
_spnQuoteVolume = new QSpinBox();
this->addWidget(_lblInstrument, 0, 1, 1, 2, Qt::AlignCenter);
this->addWidget(_lblMismatchThreshold, 1, 0, 1, 2);
this->addWidget(_lblQuoteVolume, 2, 0, 1, 2);
this->addWidget(_btnUpdateAlgo, 3, 2, 1, 2);
this->addWidget(_spnMismatchThreshold, 1, 3);
this->addWidget(_spnQuoteVolume, 2, 3);
setSizeConstraint(SetFixedSize);
}
我得到这样的东西:
但此刻我可以像下面那样调整大小:
我想禁用此类调整大小。我该怎么做?
答案 0 :(得分:3)
在主窗口中尝试:
this->layout()->setSizeConstraint(QLayout::SetFixedSize);
这是我得到的结果: