PDA

View Full Version : Issue with loading a html page on QWebEngienView through extension onto QML



ejoshva
19th June 2015, 10:52
have a QQuickWidget(ReaderMain.cpp) which has a qml (ReaderView.qml) . Also I have a QWebEngineView (WebEngineView.cpp). This WebEngineView I have extended to the qml through QMLREGISTERTYPE in ReaderMain.cpp and it's defined in another QML(BrowserWindow.qml) which is in turn included in ReaderView.qml.

Now When I try to load a page using SetHtml(). Page is not getting loaded.

I am not able to set the width and height for the WebEngineView in the QML.
error thrown as read-only property.

Kindly let me know, how can I make the page loaded and display it.

code is as below


ReaderView::ReaderView(QWidget *parent)
: QQuickWidget(parent)
{
decrypt = new Decrypt();
webView = new WebEngineView();
context = this->rootContext();
context->setContextProperty("rw",this);
qmlRegisterType<WebEngineView>("WebView",1,0,"WebEngineView");
setSource(QUrl("qrc:/ReaderView.qml"));
QQmlComponent component(engine());
component.loadUrl(QUrl("qrc:/ReaderView.qml"));
object = component.create(context);
qDebug()<<component.errors();
displayPage();
}

void ReaderView::displayPage()
{
QString content = decrypt->decryptFile("/Users/user/ssparklContent/CUPIGrade6-20150519_1977/Pages/05_preface.html", 'A');
QUrl url = QUrl("file:///Users/user/ssparklContent/CUPIGrade6-20150519_1977/Pages/05_preface.html");
QMetaObject::invokeMethod(object, "loadpage",Q_ARG(QVariant,content),Q_ARG(QVariant,url));
}

WebEngineView::WebEngineView(QWidget *parent)
: QWebEngineView(parent)
{
setGeometry(0,0,1300,800);
}
void WebEngineView::setCurrentPage(QString content, QUrl baseUrl)
{
// setHtml(content,baseUrl);
}

//ReaderView.qml
import QtQuick 2.0
Rectangle {
id: rect1
height: 800
width: 1300
color: "white"
function loadpage(pgcontent,url)
{
browserwindow.loadCurrentPage(pgcontent,url)
}
BrowserWindow {
id: browserwindow
height: parent.height - 30
width:parent.width
y:15
clip:true
}
}

//BrowserWindow.qml
import QtQuick 2.0
import WebView 1.0


Rectangle {
id:flick
height: parent.height
width: parent.width - 5

function loadCurrentPage(pagecontents, url)
{
webEngineView.setCurrentPage(pagecontents,url)

}


WebEngineView {
id: webEngineView
// height: parent.height
// width: parent.width

}
}

anda_skoa
20th June 2015, 12:12
have a QQuickWidget(ReaderMain.cpp) which has a qml (ReaderView.qml) . Also I have a QWebEngineView (WebEngineView.cpp). This WebEngineView I have extended to the qml through QMLREGISTERTYPE in ReaderMain.cpp and it's defined in another QML(BrowserWindow.qml) which is in turn included in ReaderView.qml.


Probably a typo, but QWebEngineView is the widget base view for QtWebEngine.
I.e. it is derived from QWidget, not QQuickItem.

All elements that need to be part of the visualization in a QtQuick2 scene need to be derived (directly or indirectly) from QQuickItem.

Cheers,
_

ejoshva
24th June 2015, 10:29
In that case, I wont be able to use QML elements as well.
Saw the below link explaining the same
http://stackoverflow.com/questions/17675310/embed-qwidget-object-in-qt-quick-2

I have the components already available in QML.
Please let me know, how to include those elements in QWebEngineView which is QWidget based.

For example, on mouse release on the WebEngineView, catching the same through event filter installed on the child, I will be displaying a context menu (context menu is a page in QML)

anda_skoa
24th June 2015, 12:24
Well, there are a couple of options:

1) as the stack overflow thread suggest, using a proxy to between the widget and the QtQuick2 scene
2) putting a QQuickWidget on top of the web view widget
3) using QQuickView based sub windows, e.g. for the context popup, dialogs, with the main view widget based
4) using the QQuickItem based web engine UI

Cheers,
_

ejoshva
8th July 2015, 07:33
Well, there are a couple of options:

1) as the stack overflow thread suggest, using a proxy to between the widget and the QtQuick2 scene

_
To make use of this proxy, only QGraphicsProxyWidget which is of used to set QWidgets onto QGraphicsScene is available.

Is there something similar available for QtWebEngine.

anda_skoa
8th July 2015, 08:20
There is currently no standard QQuickItem based proxy for widgets.

Cheers,
_