Draw html page using the QPainter
Question
How i can draw html page?
QWebView *view = new QWebView();
view.Load(Url("http://www.google.com"));
QPrinter printer = new Qprinter();
How I can draw this view?
Solution
In case you simply want to print the page, just use the QWebView::print(QPrinter *)
method.
If you want to draw the view to an arbitrary paint device, use QWebView::render(QPaintDevice *)
. This method is available on any QWidget
subclass.
OTHER TIPS
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{ QWebView view = new QWebView(this);
//Set settings
view->settings()->setAttribute(QWebSettings::JavaEnabled, true);
view->settings()->setAttribute(QWebSettings::JavascriptEnabled, true);
view->settings()->setAttribute(QWebSettings::JavascriptCanOpenWindows, false);
view->settings()->setAttribute(QWebSettings::JavascriptCanAccessClipboard, false);
view->settings()->setAttribute(QWebSettings::AutoLoadImages, true);
//Load URl
view->page()->mainFrame()->load(QUrl("http://www.habrahabr.ru"));
//Connect signal loadFinished
connect(view, SIGNAL(loadFinished(bool)), SLOT(finishLoading(bool)))
}
void MainWindow::finishLoading(bool)
{
//Printing
QPrinter *printer = new QPrinter(QPrinter::HighResolution);
printer->setPrinterName("Microsoft XPS Document Writer");
printer->setOutputFileName("out.xps");
view->page()->mainFrame()->print(printer);
}
Almost everything works, except for small parts. Do not tell my how to configure? FontFamily, FontSize, footer and header, link...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow