QML webview not fitting in widget layout on android.



  • Hello,
    I have a widget layout like that loads a webview within a QQuickWidget like this:

    QQuickWidget *mQuickWidget = new QQuickWidget(this);
        QUrl mSource("qrc:/webviewcontainer.qml");
        mQuickWidget->setSource(mSource);
    
        QVBoxLayout * layout=new QVBoxLayout();
    
        QPushButton * button1=new QPushButton("button1",this);
        QPushButton * button2=new QPushButton("button2",this);
    
        layout->addWidget(button1);
        layout->addWidget(mQuickWidget);
        layout->addWidget(button2);
    
        setLayout(layout);
    

    I want the webview to show up in the middle of the two buttons.But for some reason it is just ignoring the layout and showing full screen .My qml looks like this :

    import QtQuick 2.0
    import QtQuick 2.2
    import QtQuick.Controls 1.1
    import QtWebView 1.0
    import QtQuick.Layouts 1.1
    
    
    Rectangle {
        width: 1000
        height: 1800
        color: "red"
    
        ScrollView {
            id: scrollview
             anchors.fill: parent
             
            WebView {
                id: webView
                url : "http://www.blikoon.com"
            }
        }
    }
    

    I want the webview to fill the red rectangle.

    I am running this on android .Is there something I am missing or even a way around this?
    Thank for your time.


  • Moderators

    @musimbate Does setting resizeMode to QQuickWidget::SizeRootObjectToView work ?



  • No it didn't work ,the webview was still floating on top of other layed out widgets.Other QML elements fit in ok ,it is just the webview that could not. A temporary solution we used is this :
    https://github.com/gakwaya/qt-android-native-web-view-example ,I hear that when your UI is completely done in QML ,you don t have this problem ( the mini browser example is a demonstration of that.We were planning on redesigning our UI in QML anyway so this is a plus.


Log in to reply
 

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