2

I have a QGridLayout inside a QWidget. I keep adding child QGridLayouts to this. I want the QWidget to resize according to the size needed for child layouts but for the user to be unable to resize it.

MainWindow.cpp (MainWindow is inherited from 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 is inherited from 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);
}

I get something like this:

But at the moment I can resize this like:

enter image description here

I want to disable such resizing. How do I do this?

nakiya
  • 14,063
  • 21
  • 79
  • 118

1 Answers1

3

Try this in your main window:

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

This is the result i got:

enter image description here

thuga
  • 12,601
  • 42
  • 52