Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qt Academy Launch in California!

    Unsolved how to make widget (createWindowContainer) fill parent widget

    Mobile and Embedded
    3
    7
    4512
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Jian
      Jian last edited by

      I have this problem for months. I try to implement a webview on iOS with QtWebView by Qml and embed the webview into a widget by QWidget::createWindowContainer (following a online tutorial). But I just can't get this widget to fill the parent widget, nor change its size at all.

      I have write the following minimal example for explaining the problem:

      main.cpp

      #include <QApplication>
      #include <QQuickView>
      #include <QBoxLayout>
      #include <QWidget>
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
          QWidget *mainwindow = new QWidget();
          mainwindow->setStyleSheet("background-color:red;"); // so that we can see the problem more clearly
      
          QHBoxLayout *layout = new QHBoxLayout(mainwindow);
      
          QQuickView *view = new QQuickView();
          QWidget* container = QWidget::createWindowContainer(view, mainwindow);
          // container->setMinimumSize(200, 200);
          // container->setMaximumSize(200, 200); // the displaying size doesn't change with or without these lines
          // container->setFocusPolicy(Qt::TabFocus);
          view->setSource(QUrl("qrc:///webview.qml"));
      
          layout->addWidget(container);
          mainwindow->setLayout(layout);
      
          mainwindow->show();
      
          return a.exec();
      }
      

      webview.qml

      import QtQuick 2.2
      import QtWebView 1.0
      
      Item {
          visible: true
          anchors.fill: parent
          WebView {
              anchors.fill: parent
              url: "https://www.google.de"
          }
      }
      

      When I run this mini program on iphonesimulator in QtCreator, the layout is like the following screenshots: We can see the container doesn't fill the top area. And even when the parent widget is much smaller (in my actual program), the container has always this same size. When I rotate the iphonesimulator, it looks then like this!.

      Could anyone please help to solve this? It's annoying me for months. Thanks!

      JKSH 1 Reply Last reply Reply Quote 0
      • M
        mvuori last edited by

        You seem to try setting limits to the size, but for setting the size you need to use serGeometry(), setWidth() etc... according to what the mainwindow size is.

        Jian 1 Reply Last reply Reply Quote 0
        • Jian
          Jian @mvuori last edited by

          @mvuori those lines with size setting are commented. I have on Android tested, everything works and I can also change the size of container. Is this a bug on iOS?

          1 Reply Last reply Reply Quote 0
          • JKSH
            JKSH Moderators @Jian last edited by

            Have you tried QQuickWidget? It has now replaced QWidget::createWindowContainer().

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            Jian 2 Replies Last reply Reply Quote 0
            • Jian
              Jian @JKSH last edited by

              @JKSH WOW!!! With QQuickWidget is the layout perfect! Thanks! But the webview remains now white and no page (google homepage) ist displayed. Do you know why?

              JKSH 1 Reply Last reply Reply Quote 0
              • Jian
                Jian @JKSH last edited by

                @JKSH
                For example, with following code and the same webview.qml previously, I get only white screen.

                QQuickWidget *view = new QQuickWidget();
                view->setSource(QUrl("qrc:/webview.qml"));
                view->show();
                
                1 Reply Last reply Reply Quote 0
                • JKSH
                  JKSH Moderators @Jian last edited by

                  @Jian said:

                  But the webview remains now white and no page (google homepage) ist displayed. Do you know why?

                  I'm not sure, sorry. I have never used Qt WebView myself.

                  If you still can't find the answer, maybe you can subscribe to the Interest Mailing List and ask there: http://lists.qt-project.org/mailman/listinfo/interest -- Qt engineers are active in that list.

                  Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post