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
QtWS25 Last Chance

how to make widget (createWindowContainer) fill parent widget

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
7 Posts 3 Posters 5.3k Views
  • 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.
  • JianJ Offline
    JianJ Offline
    Jian
    wrote on 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!

    JKSHJ 1 Reply Last reply
    0
    • M Offline
      M Offline
      mvuori
      wrote on 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.

      JianJ 1 Reply Last reply
      0
      • M mvuori

        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.

        JianJ Offline
        JianJ Offline
        Jian
        wrote on 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
        • JianJ Jian

          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!

          JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on 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

          JianJ 2 Replies Last reply
          0
          • JKSHJ JKSH

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

            JianJ Offline
            JianJ Offline
            Jian
            wrote on 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?

            JKSHJ 1 Reply Last reply
            0
            • JKSHJ JKSH

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

              JianJ Offline
              JianJ Offline
              Jian
              wrote on 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
              • JianJ Jian

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

                JKSHJ Offline
                JKSHJ Offline
                JKSH
                Moderators
                wrote on 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

                • Login

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