Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-70305

QMdiSubWindow wrong initial size

    XMLWordPrintable

Details

    • Windows

    Description

      When calling addSubwindow on QMdiArea, whether you pass a widget or create the MdiSubWindow yourself, the subwindow ignores its own size hint. In my particular case I design a QWidget form in the UI designer that I pass to addSubwindow. This means that when the subwindow opens it doesn't have the size of the QWidget as I designed it in the designer.

      The workaround I have discovered is to resize the subwindow myself after creating it, but this isn't always easy and honestly Qt should be doing this for me. Unlike QWindow, resize sets the size of the entire QMdiSubwindow and not just the client rect, so you need to account for the frame size.
      https://stackoverflow.com/questions/19591641/initial-size-for-qmdisubwindow/29271999

        Form* form = new Form(this);
        QMdiSubWindow* subWindow = new QMdiSubWindow(this);
        subWindow->setWidget(form);
      
        // compute size of subwindow's frame
        auto borderSize = (subWindow->sizeHint() - form->sizeHint());
        auto clientSize = QSize(400,400);
        // resize the subwindow to the frame size plus desired client area
        subWindow->resize(borderSize + clientSize);
      
        // finally display the subwindow
        ui->mdiArea->addSubWindow(subWindow);
      

      The best work around seems to be overriding the size hints of the main widget for the subwindow.

        virtual QSize sizeHint() const override {
          return QSize(400,400);
        }
      

       

       

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            RobertBColton Robert B. Colton
            Votes:
            2 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes