View Full Version : How to display a html page in qgraphicswebview
ejoshva
9th February 2015, 06:29
Hi,
I want to load a html page in qgraphicswebview.
How do I do it?
I tried with something like below
QString path = "/Users/user/Desktop/tocSample/learnONNav.html";
m_p_TB_WebView->setHtml(path);
but it didn't work out.
Kindly let me know how do I display the html in qgraphicswebview.
Thanks in advance
wysota
9th February 2015, 07:37
setHtml() accepts the HTML of the page, not its file path. Have a look at setUrl().
ejoshva
9th February 2015, 08:52
m_p_TB_WebView.load(QUrl("File:/Users/user/Desktop/tocSample/learnONNav.html");
I used something like this and the html page got load.
But on click on the hyperlinks on this page, it navigates to browser(IE/Chrome) and not on the graphicwebview.
Kindly let me know, how to make the hyperlink open on graphicwebview itself.
Thanks
wysota
9th February 2015, 10:04
This works fine for me:
#include <QtWidgets>
#include <QGraphicsWebView>
int main(int argc, char **argv) {
QApplication app(argc, argv);
QGraphicsView view;
QGraphicsScene scene;
view.setScene(&scene);
QGraphicsWebView *wv = new QGraphicsWebView;
scene.addItem(wv);
view.show();
wv->setUrl(QUrl("http://www.google.com"));
return app.exec();
}
So does this:
#include <QtWidgets>
#include <QGraphicsWebView>
int main(int argc, char **argv) {
QApplication app(argc, argv);
QGraphicsView view;
QGraphicsScene scene;
view.setScene(&scene);
QGraphicsWebView *wv = new QGraphicsWebView;
scene.addItem(wv);
view.show();
QUrl url = QUrl::fromLocalFile(QFileInfo("page.html").absoluteFilePath());
qDebug() << url.toString();
wv->setUrl(url);
return app.exec();
}
with page.html being:
<html>
<body>
<div>Link: <a href="http://www.google.com">Google</a></div>
</body>
</html>
ejoshva
11th February 2015, 05:09
Can somebody throw light on how to make use of setHtml() or setContent() for QGraphicsWebView.
setUrl() is making use of file from local machine.
I want it to take file from server or from anywhere else and not from local machine.
Added after 53 minutes:
void QGraphicsWebView::setContent ( const QByteArray & data, const QString & mimeType = QString(), const QUrl & baseUrl = QUrl() )
I hope this function will suit my need as it sets the content of qgraphicswebview from the html
Can someone provide a sample for this function.
I searched a lot on net but couldn't find any for qgraphicswebview.
ejoshva
11th February 2015, 06:29
I need to load a .html file onto QGraphicsWebView.
If it's from a local machine, I could directly use
SetUrl()
But I dont want it be loaded from local machine. I want it to be loaded from the server or elsewhere.
How can this be done in Qt.
Thanks in Advance.
anda_skoa
11th February 2015, 08:12
I need to load a .html file onto QGraphicsWebView.
If it's from a local machine, I could directly use
SetUrl()
But I dont want it be loaded from local machine. I want it to be loaded from the server or elsewhere.
How can this be done in Qt.
You already know: setUrl()
Cheers,
_
ejoshva
11th February 2015, 09:28
By setUrl() , I am able to load the .html from local machine.
I want to the load the .html file from server and not local machine.
wysota
11th February 2015, 11:02
So pass a URL of the file on the server.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.