[问题]QT 打印QWebView问题

开发基于GTK+或QT的应用程序
回复
zzh.org
帖子: 46
注册时间: 2007-08-14 14:33
送出感谢: 0
接收感谢: 0

[问题]QT 打印QWebView问题

#1

帖子 zzh.org » 2008-07-31 17:15

#include "t.h"
void zhu::daor()
{
wjlj=QFileDialog::getOpenFileName(this,tr("选择csv文件"), "/", tr("csv (*.csv)"));
}
void zhu::day()
{
ssj=rq->text();
sdm=danweidaima->text();
sdw=danwei->text();
QFile file(":/zyd.html");
if (file.open(QIODevice::ReadOnly | QIODevice::Text))
{
QTextStream in(&file);
moban1 = in.readAll();
}
QPrinter *d = new QPrinter();
d->setPaperSize(QPrinter::A4);
d->setOrientation(QPrinter::Landscape);
QPrintDialog printDialog(d,this);
if (printDialog.exec() == QDialog::Accepted)
{
QFile wj(wjlj);
if (!wj.open(QIODevice::ReadOnly | QIODevice::Text))
return;
QTextStream in(&wj);
while (!in.atEnd()) {
tmp=in.readLine();
zifuchuan = tmp.split(",");
if(zifuchuan.at(0)=="t")
{
QString aa=moban1.arg(sdm)
.arg(ssj)
.arg(sdw)
.arg(zifuchuan.at(1))
.arg(zifuchuan.at(2))
.arg("")
.arg("");
wangye->setHtml(aa);
wangye->print(d);
}
else if(zifuchuan.at(0)=="z")
{
QString aa=moban1.arg(sdm)
.arg(ssj)
.arg(sdw)
.arg(zifuchuan.at(1))
.arg(zifuchuan.at(2))
.arg(zifuchuan.at(3))
.arg(zifuchuan.at(4));
wangye->setHtml(aa);
wangye->print(d);
}

}

}

}
思路是,读入一个模板,添加一些数据,然后在webview里显示,到此一切正常,下面的是wangye->print(d)不工作
----------------------------------------------------------------------------------------------------
做如下修改:

wangye->setHtml(aa);
if (printDialog.exec() == QDialog::Accepted)
{
wangye->print(d);
}}
else if(zifuchuan.at(0)=="z")
{
QString aa=moban1.arg(sdm)
.arg(ssj)
.arg(sdw)
.arg(zifuchuan.at(1))
.arg(zifuchuan.at(2))
.arg(zifuchuan.at(3))
.arg(zifuchuan.at(4));
wangye->setHtml(aa);
if (printDialog.exec() == QDialog::Accepted)
{
wangye->print(d);
}}

}
把代码改成这样就可以了,也就是说,我要打印10张,就要点10次确认,不能全自动打印,各位还有没有好办法呀?
回复

回到 “GTK+和QT”