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

QMainWindow->layout()->setSizeConstraint(QLayout::SetFixedSize) prevents window from being resizable later, even after it's cancelled

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4: Low P4: Low
    • None
    • 4.7.4, 5.2.0
    • None
    • Ubuntu 11.10

      Note: I didn't find any GUI category where to put this bug, so I choose Widgets.

      If you call

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

      on the mainwindow, your application will have a fixed size and you can't resize it. However, if later you call

      layout()->setSizeConstraint(QLayout::SetDefaultConstraint)

      , the application is still unresizable.

      So I changed the windowflags so that qt would reset the window (to add the maximize button, for one), and called show() on the main window again. Now the window is resizable but only to a certain size, there are still wild restrictions applied to it.

      mainwindow.h
      #ifndef MAINWINDOW_H
      #define MAINWINDOW_H
      
      #include <QMainWindow>
      
      class MainWindow : public QMainWindow
      {
          Q_OBJECT
      
      public:
          explicit MainWindow(QWidget *parent = 0);
      public slots:
          void changeCentralWidget();
      };
      
      #endif // MAINWINDOW_H
      
      #include "mainwindow.h"
      #include <QtGui>
      
      MainWindow::MainWindow(QWidget *parent) :
          QMainWindow(parent)
      {
          show();
          setCentralWidget(new QPushButton("hello, this is a test................"));
          layout()->setSizeConstraint(QLayout::SetFixedSize);
      
          connect(centralWidget(), SIGNAL(clicked()), SLOT(changeCentralWidget()));
      }
      
      void MainWindow::changeCentralWidget()
      {
          layout()->setSizeConstraint(QLayout::SetDefaultConstraint);
          setCentralWidget(new QTextEdit(QString::number(windowFlags(), 16)));
          layout()->setSizeConstraint(QLayout::SetDefaultConstraint);
      
          /* Adds the possibility to resize the window */
          setWindowFlags(windowFlags() ^ Qt::WindowMinMaxButtonsHint);
          setWindowFlags(windowFlags() | Qt::WindowMinMaxButtonsHint);
          show();
      }
      

      Context

      I have an application with an image as a menu, and as such fixed size. But then when the user gets into different functionalities, they make the window have a different layout and be resizable. For now what I do is create a new QMainWindow and delete the old one everytime, however now on ubuntu if you have another app on the same screen, it makes my application go behind it. That's why I'm submitting this bug report. I've had this bug since I started, around Qt 4.5, and on windows too.

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

            smd Jan Arve
            coyotte508 coyotte508
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes