how to make widget (createWindowContainer) fill parent widget
-
wrote on 25 Feb 2016, 09:34 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!
-
wrote on 25 Feb 2016, 09:54 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.
-
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.
-
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!
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?
@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.
1/7