Details
-
Bug
-
Resolution: Duplicate
-
P3: Somewhat important
-
None
-
5.0.1, 5.1.0 RC1
-
None
-
Windows 7/32bit, Qt 5.0.1
Description
I tried displaying the simple HTML file in the qwebview, and sending the same to the printer. But Unfortunatly the output is not aligned properly.
Here is the Code:
myView.h:
---------
class myView : public QWebView
{ Q_OBJECT public: explicit myView(QWidget * parent = 0); private slots: void onLoadFinished(bool b); };
MyView.cpp:
-----------
myView::myView(QWidget *parent):QWebView(parent)
{
QObject::connect(page()->mainFrame(), SIGNAL(loadFinished(bool)), SLOT(onLoadFinished(bool)));
setHtml("<html><body>Welcome <br> <table border=1> <tr><td> row1,col1 </td></tr><tr><td>row2, Col1</td></tr></table> </body></html>");
}
void myView::onLoadFinished(bool b)
{
settings()->setAttribute(QWebSettings::PrintElementBackgrounds, true);
QPrinter printer;
printer.setPageSize(QPrinter::A4);
printer.setOrientation(QPrinter::Portrait);
QPrintDialog *dlog = new QPrintDialog (&printer, this);
if ( dlog->exec () == QDialog::Accepted)
{ print(&printer); }}
Main.cpp:
---------
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
myView *mv = new myView();
mv->show();
return a.exec();
}
Have tried setting several options to the QPrinter, but the result is the same.