<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html><head><meta http-equiv="content-type" content="text/html; charset=cp-1251" /><style type="text/css" title="currentStyle"> BODY { width: 180mm; border: 1px solid black; }</style></head><body>123</body></html>
QPrinter printer; QPrintPreviewDialog printDialog(&printer); printDialog.printer()->setPaperSize(QPrinter::A4); printDialog.printer()->setOrientation(QPrinter::Portrait); printDialog.printer()->setPageMargins(10.0,10.0,10.0,10.0,QPrinter::Millimeter); printDialog.printer()->setFullPage(true); connect(&printDialog, SIGNAL(paintRequested(QPrinter *)), m_ui->webView, SLOT(print(QPrinter *))); printDialog.exec();
void Dialog::on_pushButton_clicked(){ QPrinter printer; QPrintPreviewDialog printDialog(&printer); printDialog.printer()->setPaperSize(QPrinter::A4); printDialog.printer()->setOrientation(QPrinter::Portrait); printDialog.printer()->setPageMargins(0.0,0.0,0.0,0.0,QPrinter::Millimeter); printDialog.printer()->setFullPage(false); connect(&printDialog, SIGNAL(paintRequested(QPrinter *)), this, SLOT(pprew(QPrinter *))); printDialog.exec();}void Dialog::pprew(QPrinter *prnt){ QPainter painter(prnt); painter.setRenderHint(QPainter::Antialiasing); painter.setPen(Qt::darkGreen); painter.drawRect(0, 0,prnt->paperSize(QPrinter::Point).width(), prnt->paperSize(QPrinter::Point).height());}
printDialog.printer()->setResolution(72);
void QWebFrame::print(QPrinter *printer) const{ QPainter painter; if (!painter.begin(printer)) return; const qreal zoomFactorX = printer->logicalDpiX() / qt_defaultDpi(); const qreal zoomFactorY = printer->logicalDpiY() / qt_defaultDpi(); PrintContext printContext(d->frame); float pageHeight = 0; QRect qprinterRect = printer->pageRect(); IntRect pageRect(0, 0, int(qprinterRect.width() / zoomFactorX), int(qprinterRect.height() / zoomFactorY));
qt_defaultDpi();
const qreal zoomFactorX = printer->logicalDpiX() / qt_defaultDpi(); const qreal zoomFactorY = printer->logicalDpiY() / qt_defaultDpi();
qDebug("zoomFactorX %f", zoomFactorX);
IntRect pageRect(0, 0, int(qprinterRect.width() / zoomFactorX), int(qprinterRect.height() / zoomFactorY));
const qreal zoomFactorX = printer->logicalDpiX() / qt_defaultDpi();
const qreal zoomFactorX = (qreal)printer->logicalDpiX() / (qreal)qt_defaultDpi();