我如何绘制html页面?
QWebView *view = new QWebView();
view.Load(Url("http://www.google.com"));
QPrinter printer = new Qprinter();
我如何绘制这个视图?
答案 0 :(得分:1)
如果您只想打印页面,只需使用QWebView::print(QPrinter *)
方法。
如果要将视图绘制到任意绘图设备,请使用QWebView::render(QPaintDevice *)
。此方法适用于任何QWidget
子类。
答案 1 :(得分:0)
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);
}
除了小零件外,几乎所有东西都能正常工作。不要告诉我如何配置? FontFamily,FontSize,页脚和标题,链接......