我正在尝试将文本集中在普通 A4 尺寸的作品集中,获得的尺寸是正确的,但它没有居中,我不知道原因是什么,这里我向您展示代码
from PyQt4.QtGui import QPrinter,QPainter,QApplication
from PyQt4.QtCore import Qt,QRectF
import sys
app = QApplication(sys.argv)
printer = QPrinter()
painter = QPainter()
printer.setOutputFileName("prueba.pdf")
printer.setOutputFormat(QPrinter.PdfFormat)
printer.setPageMargins(0.0,0.0,0.0,0.0,1)
printer.setFullPage(True)
margin = printer.getPageMargins(1)
print margin
size = printer.paperSize(1)
width = size.width()
print width
painter.begin(printer)
painter.drawText(QRectF(0.0,0.0,width,50.0),Qt.AlignCenter|Qt.AlignTop,"abcdefghijklmn")
painter.end()
如您所见,我得到了对开类型点大小的宽度,并且将对开的整个宽度不均匀