Changing the Windows display scaling to 125% or 150% does not affect printing the Google front page for me. The test code I used is below.
What is the HTML you are loading? Is it well formed? Does it use styles with fixed widths? External CSS? Javascript?
#include <QApplication>
#include <QWebView>
#include <QPrinter>
#include <QDebug>
class MyWebView: public QWebView
{
Q_OBJECT
public:
MyWebView
(QWidget *p
= 0): QWebView
(p
) { connect(this, SIGNAL(loadFinished(bool)), SLOT(doPrint(bool)));
}
public slots:
void doPrint(bool ok) {
qDebug() << "doPrint" << ok;
printer.
setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName("zz.pdf");
printer.setFullPage(true);
printer.
setOrientation(QPrinter::Portrait);
print(&printer);
qDebug() << "doPrint done";
}
};
int main(int argc, char **argv)
{
MyWebView web;
web.
setUrl(QUrl("http://www.google.com.au"));
web.show();
return app.exec();
}
#include "main.moc"
#include <QApplication>
#include <QWebView>
#include <QPrinter>
#include <QDebug>
class MyWebView: public QWebView
{
Q_OBJECT
public:
MyWebView(QWidget *p = 0): QWebView(p) {
connect(this, SIGNAL(loadFinished(bool)), SLOT(doPrint(bool)));
}
public slots:
void doPrint(bool ok) {
qDebug() << "doPrint" << ok;
QPrinter printer;
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName("zz.pdf");
printer.setFullPage(true);
printer.setOrientation(QPrinter::Portrait);
printer.setPaperSize(QPrinter::A4);
print(&printer);
qDebug() << "doPrint done";
}
};
int main(int argc, char **argv)
{
QApplication app(argc, argv);
MyWebView web;
web.setUrl(QUrl("http://www.google.com.au"));
web.show();
return app.exec();
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode
Bookmarks