c++ - Qt QWidget 禁用调整大小超过所需的最小大小

标签 c++ qt layout

我有一个QGridLayout里面 QWidget 。我不断添加 child 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);
}

我得到这样的信息:

但目前我可以调整其大小:

enter image description here

我想禁用这种大小调整。我该怎么做?

最佳答案

在主窗口中尝试一下:

this->layout()->setSizeConstraint(QLayout::SetFixedSize);

这是我得到的结果:

enter image description here

关于c++ - Qt QWidget 禁用调整大小超过所需的最小大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21774054/

相关文章:

html - 折叠到其子项高度的 CSS 水平条(获得不需要的垂直空间)

jquery - 水平滚动布局左/右: jQuery/CSS quiz

wpf - WPF中的大小到内容布局问题

c++ - 使用 grep 命令一个 .hpp 文件获得匹配的二进制文件

c++ - 与 setw() 有什么关系?

c++ - Windows 多任务破坏了 OpenCL 性能

c++ - 读/写 QObject

c++ - 10341 - 西澳解决

Javascript 不使用 QWebView cookie/ session

c++ - 窗口QTCreator的创建、处理和切换