3
我正在寫一個應用程序,可以將地址直接打印到信封上。我正在使用QTextDocument,問題是它的方法print()添加頁碼,這在信封中是不正確的。QTextDocument中用於信封的頁碼
一些代碼,如果你需要它:
void MainWindow::print()
{
QString addressText = textEdit->document()->toPlainText();
envelopeDocument = new QTextDocument(this);
printer.setResolution(QPrinter::HighResolution);
printer.setPrinterName("OKI B6200(PCL6)");
printer.setOrientation(QPrinter::Landscape);
QFont font("Trebuchet MS");
switch (envelopeComboBox->currentIndex()){
case 0:
font.setPointSize(12);
envelopeDocument->setDefaultFont(font);
envelopeDocument->setPlainText(addressText);
printer.setPaperSize(QSizeF(114,225),QPrinter::Millimeter);
printer.setPageMargins(120,60,20,15,QPrinter::Millimeter);
break;
case 1:
font.setPointSize(14);
envelopeDocument->setDefaultFont(font);
envelopeDocument->setPlainText(addressText);
printer.setPaperSize(QSizeF(184,262),QPrinter::Millimeter);
printer.setPageMargins(140,100,20,20,QPrinter::Millimeter);
break;
case 2:
font.setPointSize(16);
envelopeDocument->setDefaultFont(font);
envelopeDocument->setPlainText(addressText);
printer.setPaperSize(QSizeF(227,324), QPrinter::Millimeter);
printer.setPageMargins(170,120,30,40,QPrinter::Millimeter);
break;
}
QPrintPreviewDialog preview (&printer,this);
preview.setWindowFlags(Qt::Window);
connect(&preview, SIGNAL(paintRequested(QPrinter *)),SLOT(printPreview(QPrinter *)));
preview.exec();
}
void MainWindow::printPreview(QPrinter *p)
{
envelopeDocument->print(p);
}
謝謝!
thanx,我會試試這個,回到你身邊... – shofee 2012-02-24 11:53:55
thanx ken它爲我工作... – shofee 2012-02-24 11:56:09