how to make widget (createWindowContainer) fill parent widget



  • 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!



  • 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.



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


  • Moderators

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



  • @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
    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();
    

  • Moderators

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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.