문제

So the non-QMdiArea version of my code,

MyWidget::MyWidget(QWidget* parent)
{
   ...
   layout()->setSizeConstraint( QLayout::SetFixedSize );
}

MainWindow::MainWindow(...)
{
   ...
   MyWidget* wgt = new MyWidget(NULL);
   wgt->show();
}

works just fine and produces a widget that the user can't resize. But when the MainWindow code is replaced with

MainWindow::MainWindow(...)
{
   ...
   MyWidget* wgt = new MyWidget(ui->mdiArea); //Or MyWidget(NULL), same result
   ui->mdiArea->addSubWindow(wgt);
}

the window, now within the QMdiArea, is resizeable. It doesn't seem to be an issue of Qt::WindowFlags, they don't handle resize policy. Surely there is a way to do this? NB I cant use something like setFixedSize(ht, wd) since the size of the widget can change programmatically (subwidgets are added and removed). But the user should not be able to resize it.

도움이 되었습니까?

해결책

The following worked for me:

    MyWidget* wgt = new MyWidget(ui->mdiArea); 
    QMdiSubWindow* subWindow = ui->mdiArea->addSubWindow(wgt); 
    subWindow->setFixedSize(wgt->size());
    wgt->show();

다른 팁

Even though MyWidget is not resizeable, when you call:

ui->mdiArea->addSubWindow(wgt);

The widget is put in a QMdiSubWindow which is resizeable. All you have to do is get the window that's created and fix its size:

QMdiSubWindow* subWindow = ui->mdiArea->addSubWindow(wgt);
subWindow->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);

This should work, but I haven't tried this code myself.

EDIT: well... apparently that doesn't fix the size. :(

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top