Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Consider the following QML snippet:

Page {
    WebView {
        id: webView
        anchors.fill: parent
    }
}

I then attempt to load some HTML in the WebView using the following JavaScript:

webView.loadHtml('<b>test</b>');

However, the WebView has a white background:

enter image description here

(Ignore the fact that the text is too small.)

Is there a way to make the background transparent?

share|improve this question

1 Answer 1

up vote 5 down vote accepted

You could try QtWebKit.experimental. If you add import QtWebKit.experimental 1.0 to your QML files, your WebView objects will have access to experimental attributes:

import QtQuick 2.0
import QtWebKit.experimental 1.0
import Ubuntu.Components 0.1


MainView {
    id: main
    width: units.gu(100)
    height: units.gu(75)

    Page {
        id: mypage
        Rectangle {
            color: "green"
            anchors.fill: mypage
            WebView {
                id: webView
                anchors.fill: parent
                experimental.transparentBackground: true
            }
        }

        Component.onCompleted: webView.loadHtml("<p>Hello</p>");
    }
}

Obviously you'll get this kind of warning:

WARNING: The experimental API will change from version to version, or even be removed. You have been warned!

share|improve this answer
    
Thanks. Are there any implications of using an older version of QtWebKit? (The latest version is 3.0.) –  Nathan Osman Mar 18 at 6:42
    
You can use both at the same time, import QtWebKit.experimental 1.0 AND import QtWebKit 3.0 –  Sylvain Pineau Mar 18 at 8:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.