如何在真正的打印机中修复QPainter :: drawText时出现“ EndPage failed”错误

时间:2019-09-11 08:43:17

标签: c++ qt qpainter drawtext

我正在尝试在Windows 7 x64上使用Qt 5.8.0在HP Deskjet 2130中打印一些卡片,该文件是使用Visual Studio 2013 Ultimate编译的。

void MainWindow::on_pushButton_clicked()
{
    int         inNumeros[] = {5, 14, 23, 32, 41, 50 };
    int         inLinha, inColuna, inValor;
    int         inY = 2260;
    int         inX = 700;
    int         inForm2Y = 2500;
    int         inForm2X = 100;
    QPrinter    oPrinter(QPrinter::HighResolution);
    QPainter    oPainter;

    QPrintDialog dialog(&oPrinter);
    dialog.setWindowTitle(tr("Imprimir Volantes"));
    dialog.addEnabledOption(QAbstractPrintDialog::PrintSelection);
    if (dialog.exec() != QDialog::Accepted) {
        //qDebug() << dialog.printRange();
        return;
    }
    //int     inInicial   = oPrinter.fromPage();
    //int     inFinal     = oPrinter.toPage();

    QPageSize   oPageSize(QSizeF(80, 185), QPageSize::Millimeter);
    QRect       obRetangulo(inX + inForm2X, inY + inForm2Y, 395, 200);

    oPrinter.setPageSize(oPageSize);
    oPrinter.setPageMargins(QMarginsF(0, 0, 0, 0), QPageLayout::Millimeter);
    oPainter.begin(&oPrinter);
    oPainter.setWindow(0, 0, 8000, 18500); // A 80 mm x 185 mm form

    for(int inConta = 0; inConta < 6; inConta++) {
        inValor = inNumeros[inConta];

        inLinha = ((inValor - 1) / 10);
        inColuna = ((inValor - 1 ) % 10);

        oPainter.setPen(QPen(Qt::black, 3.0, Qt::SolidLine));
        oPainter.setBrush(Qt::black);
        obRetangulo.setY(inY + (inLinha * 370) + inForm2Y);
        obRetangulo.setX(inX + (inColuna * 750) + inForm2X);
        obRetangulo.setWidth(395);
        obRetangulo.setHeight(200);

        oPainter.drawRect( obRetangulo );

        QString szTemp = QString("%1 %2 %3").arg(14, 2).arg("SisMega ").arg("2188");
        oPainter.setFont(QFont("Tahoma", 30));
        QRectF oRectPos(4500, 330 + inForm2Y, 100, 100);
        qDebug() << szTemp << " / " << oRectPos ;

        //oPainter.drawText( oRectPos, Qt::AlignLeft, szTemp, &oRectPos );
        //oPainter.drawText( oRectPos, Qt::AlignLeft, szTemp, &oRectPos );
    }
    oPainter.end();
}

这很好,但是如果我用.drawText()取消注释行,则不会打印任何内容,并且会出现“ QWin32PrintEngine :: end:EndPage失败(0x842122f5)()”错误...

此代码在Qt 5.5.1(相同环境)中可以正常工作...

谢谢。

0 个答案:

没有答案