Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. how to make widget (createWindowContainer) fill parent widget
Forum Updated to NodeBB v4.3 + New Features

how to make widget (createWindowContainer) fill parent widget

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
7 Posts 3 Posters 5.3k Views 1 Watching
  • 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.
  • J Offline
    J Offline
    Jian
    wrote on 25 Feb 2016, 09:34 last edited by
    #1

    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!

    J 1 Reply Last reply 25 Feb 2016, 14:11
    0
    • M Offline
      M Offline
      mvuori
      wrote on 25 Feb 2016, 09:54 last edited by
      #2

      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.

      J 1 Reply Last reply 25 Feb 2016, 13:31
      0
      • M mvuori
        25 Feb 2016, 09:54

        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.

        J Offline
        J Offline
        Jian
        wrote on 25 Feb 2016, 13:31 last edited by
        #3

        @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
        0
        • J Jian
          25 Feb 2016, 09:34

          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!

          J Offline
          J Offline
          JKSH
          Moderators
          wrote on 25 Feb 2016, 14:11 last edited by
          #4

          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

          J 2 Replies Last reply 25 Feb 2016, 15:16
          0
          • J JKSH
            25 Feb 2016, 14:11

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

            J Offline
            J Offline
            Jian
            wrote on 25 Feb 2016, 15:16 last edited by
            #5

            @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?

            J 1 Reply Last reply 26 Feb 2016, 13:45
            0
            • J JKSH
              25 Feb 2016, 14:11

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

              J Offline
              J Offline
              Jian
              wrote on 25 Feb 2016, 15:56 last edited by
              #6

              @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
              0
              • J Jian
                25 Feb 2016, 15:16

                @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?

                J Offline
                J Offline
                JKSH
                Moderators
                wrote on 26 Feb 2016, 13:45 last edited by
                #7

                @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
                0

                1/7

                25 Feb 2016, 09:34

                • Login

                • Login or register to search.
                1 out of 7
                • First post
                  1/7
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved