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

Child QQuickWidget doesn't handle geometry change (e.g. when moving widgets in a layout)

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 5.3.0 Beta1
    • 5.3.0 Beta1
    • Quick: Other
    • None
    • afbad00a4d9ff28967ca15e0f9029925e86f2cf4

    Description

      Take the qquickwidget example and replace main.cpp with this:

      #include <QQuickWidget>
      #include <QtWidgets>
      
      class HideShow : public QObject {
          Q_OBJECT
      public:
      
          QWidget *subject;
          HideShow(QWidget *subject, int interval) : QObject(subject), subject(subject)
          {
              startTimer(interval);
          }
      
          void timerEvent(QTimerEvent *)
          {
              if (subject->isVisible()) {
                  subject->hide();
              } else {
                  subject->show();
              }
          }
      };
      
      int main(int argc, char **argv)
      {
          QApplication app(argc, argv);
          QWidget *toplevel = new QWidget;
      
          QVBoxLayout *groupLayout = new QVBoxLayout;
          QUrl source("qrc:quickwidget/rotatingsquare.qml");
      
          QQuickWidget *above = new QQuickWidget;
          above->setResizeMode(QQuickWidget::SizeRootObjectToView);
          above->setSource(source);
          above->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
          above->setFixedHeight(50);
          groupLayout->addWidget(above);
      
          QQuickWidget *w = new QQuickWidget;
          w->setResizeMode(QQuickWidget::SizeRootObjectToView);
          w->setSource(source);
          w->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
          groupLayout->addWidget(w);
      
          QQuickWidget *below = new QQuickWidget;
          below->setResizeMode(QQuickWidget::SizeRootObjectToView);
          below->setSource(source);
          below->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
          below->setFixedHeight(50);
          groupLayout->addWidget(below);
      
          new HideShow(w, 3000);
          toplevel->setMinimumHeight(170);
          toplevel->setLayout(groupLayout);
          toplevel->show();
          return app.exec();
      }
      
      #include "main.moc"
      

      When the central widget is hidden the two others move to the middle. When it's shown again they don't move back. Now compare that with:

      #include <QQuickWidget>
      #include <QtWidgets>
      
      class HideShow : public QObject {
          Q_OBJECT
      public:
      
          QWidget *subject;
          HideShow(QWidget *subject, int interval) : QObject(subject), subject(subject)
          {
              startTimer(interval);
          }
      
          void timerEvent(QTimerEvent *)
          {
              if (subject->isVisible()) {
                  subject->hide();
              } else {
                  subject->show();
              }
          }
      };
      
      int main(int argc, char **argv)
      {
          QApplication app(argc, argv);
          QWidget *toplevel = new QWidget;
      
          QVBoxLayout *groupLayout = new QVBoxLayout;
      
          QLCDNumber *above = new QLCDNumber;
          above->display(1337);
          above->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
          above->setFixedHeight(50);
          groupLayout->addWidget(above);
      
          QLCDNumber *w = new QLCDNumber;
          w->display(1338);
          w->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
          groupLayout->addWidget(w);
      
          QLCDNumber *below = new QLCDNumber;
          below->display(1339);
          below->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
          below->setFixedHeight(50);
          groupLayout->addWidget(below);
      
          new HideShow(w, 3000);
          toplevel->setMinimumHeight(170);
          toplevel->setLayout(groupLayout);
          toplevel->show();
          return app.exec();
      }
      
      #include "main.moc"
      

      The LCD widgets move correctly when the layout changes.

      Attachments

        Issue Links

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

          Activity

            People

              tvete Paul Olav Tvete
              ulherman Ulf Hermann
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes