C++ Qt QWidget禁用重新调整大小超过所需的最小大小

C++ Qt QWidget禁用重新调整大小超过所需的最小大小,c++,qt,layout,C++,Qt,Layout,我在QWidget中有一个QGridLayout。我一直在添加childQGridLayouts。我想让QWidget根据子布局所需的大小调整大小,但用户无法调整大小 MainWindow.cpp(MainWindow继承自QWidget) AAController.cpp(AAController继承自QGridLayout) 我得到这样的东西: 但目前我可以调整它的大小,如: 我想禁用这种大小调整。如何执行此操作?在主窗口中尝试此操作: this->layout()->set

我在
QWidget
中有一个
QGridLayout
。我一直在添加child
QGridLayouts
。我想让
QWidget
根据子布局所需的大小调整大小,但用户无法调整大小

MainWindow.cpp(
MainWindow
继承自
QWidget

AAController.cpp(
AAController
继承自
QGridLayout

我得到这样的东西:

但目前我可以调整它的大小,如:


我想禁用这种大小调整。如何执行此操作?

在主窗口中尝试此操作:

this->layout()->setSizeConstraint(QLayout::SetFixedSize);
这是我得到的结果:


只需将主窗口设置为固定大小即可。添加子项时,将其设置为最小值,并在之后将其设置为固定大小。可能不会重复,因为它既没有状态栏,也没有QDialog。@SebastianRange:您的方法会产生固定大小的窗口。但大于上面第一幅图中的最小值。
main窗口中的
setFixedSize(0,0)
。它在窗口的边框上显示了调整大小的光标,但实际上无法调整大小。请查看SebastianLange的注释above@nakiya请参阅我的编辑。这就是你想要的结果吗?是的,我想要的。谢谢
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);
}
this->layout()->setSizeConstraint(QLayout::SetFixedSize);