简体   繁体   中英

PySide6 setPageMargins()

I tried setting qprinter margins in PySide6 it throws an error

PySide6.QtGui.QPagedPaintDevice.setPageMargins(): too many arguments

    document = QtGui.QTextDocument()
    p = QtPrintSupport.QPrinter()
    p.setResolution(100)
    
    p.setPageMargins(1, 6, 1, 1, QtPrintSupport.QPrinter().Millimeter)
    document.setPageSize(QSizeF(p.pageRect().size()))

this works on PyQt5

It seems that PySide6 is more strict with enums and does not auto-convert like PyQt5 so the code should be:

document = QtGui.QTextDocument()
p = QtPrintSupport.QPrinter()
p.setResolution(100)

p.setPageMargins(QtCore.QMargins(1, 6, 1, 1), QtGui.QPageLayout.Millimeter)
document.setPageSize(
    QtCore.QSizeF(p.pageRect(QtPrintSupport.QPrinter.Millimeter).size())
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM