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

QWidget::adjustSize limits the size of toplevel windows to 2/3'rd of the screen size

    XMLWordPrintable

Details

    Description

      This makes it impossible to design fixed-size dialogs that are larger than that. I.e. if the sizeHint of the dialog is i.e. 750 x 500, which is a perfectly valid size for a 800x600 display, then the dialog will actually show up with a size of 533 x 333 pixels:

      #include <QtGui>

      class Dialog : public QDialog
      {
      public:
      Dialog()

      { QHBoxLayout *hbox = new QHBoxLayout; // reasonably large display QLabel *display = new QLabel; QSize screenSize = QApplication::desktop()->screenGeometry().size(); screenSize -= QSize(50, 100); display->setFixedSize(screenSize); qDebug() << "Preferred display size:" << screenSize; hbox->addWidget(display); setLayout(hbox); }

      protected:
      void resizeEvent(QResizeEvent *e)

      { qDebug() << "Actual window size: " << size(); }

      };

      int main (int argc, char** argv)
      {
      QApplication app(argc, argv);

      Dialog w;
      w.adjustSize();
      w.setFixedSize(w.size());
      w.show();

      return app.exec();
      }

      The responsible code is in qwidget.cpp in the adjustSize function:

      s.setWidth(qMin(s.width(), screen.width()*2/3));
      s.setHeight(qMin(s.height(), screen.height()*2/3));

      If the widget is not resized explicitly as above, then Qt will call adjustSize() when showing the widget, and in that case not limit the size to the screen. This allows the workaround to set the resizeMode of the layout instead to QLayout::Fixed, i.e.

      w.layout()->setResizeMode(QLayout::Fixed);

      Attachments

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

        Activity

          People

            vfm Thierry Bastian (closed Nokia identity) (Inactive)
            vhilshei Volker Hilsheimer
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes