如何使用Qt Prin在Qt中设置paperSize==pageSize

2024-04-19 05:17:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用QPrinter在qt应用程序中打印支票。但我试过的都不管用

我正在qt中构建支票打印应用程序。但当我开始印刷时,它并没有得到正确的印刷。总之,这张支票用纸不合适。我已经尝试了这里和qt论坛给出的所有建议,但似乎不起作用。我有设置页面大小,设置纸张大小等没有工作。内容没有印在整张纸上。我还为pageSize添加了一个矩形。我想让这个长方形占据整张纸。你知道吗

我正在努力解决这个问题。如果有人能找到解决办法,我会很高兴的。谢谢

这里有一些代码,我试过了

width = 576.000880
height = 263.520403

printer = QPrinter()
printer.setPageSize(QPageSize(QSizeF(width, height), QPageSize.Unit.Point, 'Cheque'))
printer.setFullPage(True)

painter = QPainter(printer).
painter.begin()

painter.drawRect(QRect(0, 0, width, height))
painter.drawText(QPointF(payee_x, payee_y), payee)
painter.drawText(QPointF(amount_x, amount_y), amount)
painter.drawText(QPointF(amount_in_words_x, amount_in_words_y), amount_in_words)
painter.drawText(QPointF(date_x, date_y), date)

painter.end()

预期结果:

预期

enter image description here

错误

enter image description here


Tags: in应用程序dateqtwidthamountprinterwords