[转] QT 小票打印

原地址: http://www.cppblog.com/biao/archive/2009/09/08/95603.html

 

   QString htmlString = QString("<html>") + str1 + str2 +str3 + finerysInfo + str5 + str6

                  + QString("<br>%1<br>%2").arg(separateString) + QString("</html>");

    printString(htmlString);

 

    accept();

}

 

void PrintDialog::printString(const QString &htmlString) {

    qDebug() << htmlString;

 

    QPrinter p;

    QTextDocument doc;

    //doc.setHtml(htmlString);

 

    QFont font = doc.defaultFont();

    font.setBold(true);

    font.setPointSize(font.pointSize() + 1);

    doc.setDefaultFont(font);

 

    QSizeF s = QSizeF(p.logicalDpiX() * (58 / 25.4), p.logicalDpiY() * (297 / 25.4));

    doc.setPageSize(s);

 

    p.setOutputFormat(QPrinter::NativeFormat);

 

    // N

    int pageCount = ui->pageCountLineEdit->text().toInt();

    for (int i = 1; i <= pageCount; ++i) {

        // 如果只打印一份,即只打印店

        if (1 == pageCount) {

            if (Receive_Finery == operationType) {

                doc.setHtml(htmlString.arg(tr("")));

            } else {

                doc.setHtml(htmlString.arg(tr("户联")));

            }

        } else {

            if (i % 2 != 0) {

                doc.setHtml(htmlString.arg(tr("户联")));

            } else {

                doc.setHtml(htmlString.arg(tr("")));

            }

        }

        doc.print(&p);

 

        if (i < pageCount) {

            p.newPage();

        }

    }

}

 

posted @ 2010-09-08 22:03  网络小虫  阅读(1067)  评论(0编辑  收藏  举报