2010-07-06 81 views
1

如何绘制html页面?使用QPainter绘制html页面

QWebView *view = new QWebView(); 
view.Load(Url("http://www.google.com")); 

QPrinter printer = new Qprinter(); 

我该如何画这个视图?

回答

1

如果您只是想打印页面,只需使用QWebView::print(QPrinter *)方法即可。

如果要将视图绘制到任意涂料设备,请使用QWebView::render(QPaintDevice *)。此方法适用于任何QWidget子类。

+0

我想通过Microsoft Xps打印机进行打印。 QPrinter.setPrinterName(“Microsoft Xps Printer”); – isxaker 2010-07-06 16:59:47

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,页脚和标题,链接...