【问题标题】:Qt QWidget disable re sizing more than minimum size needed [duplicate]Qt QWidget禁用调整大小超过所需的最小大小[重复]
【发布时间】:2014-03-13 12:01:23
【问题描述】:

我在QWidget 中有一个QGridLayout。我一直在添加孩子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);
}

我得到这样的东西:

但目前我可以像这样调整大小:

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

【问题讨论】:

  • 只需将主窗口设置为固定大小。添加儿童时将其设置为最小并在之后将其设置回固定大小。
  • 可能不重复,因为它既没有 StatusBar 也没有 QDialog。
  • @SebastianLange:您的方法会生成固定大小的窗口。但大于上面第一张图片中的最小值。
  • setFixedSize(0,0)MainWindow 工作。它在窗口的边框处显示调整大小的光标,但实际上无法调整大小。

标签: c++ qt layout


【解决方案1】:

在您的主窗口中试试这个:

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

这是我得到的结果:

【讨论】:

  • 请看上面对 SebastianLange 的评论
  • @nakiya 查看我的编辑。这是您要寻找的结果吗?
  • 是的,我在找什么。谢谢。
猜你喜欢
  • 2011-11-23
  • 1970-01-01
  • 2012-02-15
  • 1970-01-01
  • 1970-01-01
  • 2019-10-20
  • 1970-01-01
  • 2016-03-12
  • 1970-01-01
相关资源
最近更新 更多