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

In QMdiSubWindow heightForWidth() does not work.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 4.8.5, 5.2.0
    • None

    Description

      Setting heightForWidth() to true does not work with QMdiSubWindow. Tried setting it both to QMdiSubWindow and to the containing widget. Here is an example, which shows how it works in plain QWidget but not when placed to QMdiArea.

      #include <QApplication>
      #include <QWidget>
      #include <QDebug>
      #include <QVBoxLayout>
      #include <QMdiArea>
      #include <QMainWindow>
      #include <QMdiSubWindow>
      
      
      class OwnSubWindow : public QMdiSubWindow {
          mutable int m_ctr;
      public:
          OwnSubWindow(QWidget *parent = 0) : QMdiSubWindow(parent), m_ctr(0) {
              QSizePolicy p(sizePolicy());
              p.setHeightForWidth(true);
              setSizePolicy(p);
          }
          int heightForWidth(int width) const {
              qDebug()<<"heightforwidth "<<m_ctr;
              m_ctr ++;
              qApp->postEvent(const_cast<OwnSubWindow*>(this), new QEvent(QEvent::UpdateRequest));
              return qMax(width*2, 100);
          }
          QSize sizeHint() const {
              return QSize(300, heightForWidth(300));
          }
      };
      
      class Widget : public QWidget {
          mutable int m_ctr;
      public:
          Widget(QWidget *parent = 0) : QWidget(parent), m_ctr(0) {
              QSizePolicy p(sizePolicy());
              p.setHeightForWidth(true);
              setSizePolicy(p);
          }
          int heightForWidth(int width) const {
              qDebug()<<"heightforwidth "<<m_ctr;
              m_ctr ++;
              QApplication::postEvent(const_cast<Widget*>(this), new QEvent(QEvent::UpdateRequest));
              return qMax(width*2, 100);
          }
          QSize sizeHint() const {
              return QSize(300, heightForWidth(300));
          }
      };
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
      
          QMainWindow w1;
          QMdiArea *mdiArea = new QMdiArea();
      
          mdiArea->addSubWindow(new OwnSubWindow);
          mdiArea->addSubWindow(new Widget);
      
          w1.setCentralWidget(mdiArea);
          w1.show();
      
          QWidget w;
          QVBoxLayout * l = new QVBoxLayout(&w);
          l->addWidget(new Widget);
          w.show();
          return a.exec();
      }
      

      Attachments

        Issue Links

          For Gerrit Dashboard: QTBUG-36220
          # Subject Branch Project Status CR V

          Activity

            People

              tvete Paul Olav Tvete
              qtcomsupport Qt Support
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes