Remove the Margins of a QtextEdit or QtextDocument when printing.
Hi,
I have a QTextEdit filled with just HTML and I want to print it (either to any print or as PDF). However, the output file always shows way too much margins or borders and I want to remove them.
https://image.prntscr.com/image/0mpZ...sdCPrGTY7w.png
This is my PyQt5 Code:
Code:
printer = setupdialog.printer()
textReport.print(printer)
textReport is a QtextEdit() created with Qt Creator for a .ui file (I can control how the html looks like inside the QtextEdit that way and I can guarantee it show no margins at all in Qt Creator Design mode).
I've also tried all of this options separately:
Code:
printer.
setPageMargins(0.1,
0.1,
0.1,
0.1,
QPrinter.
Millimeter) #left top right bottomprinter.setFullPage(True)
printer.
setPageMargins(QPrinter.
Millimeter)printer.
setPageRect(QPrinter.
Millimeter)printer.
setPaperRect(QPrinter.
Millimeter)printer.setPageSizeMM()
printer.setResolution()
printer.setPaperName()
textReport.setContentsMargins(0, 0, 0, 0)
I also tried to use a QtextDocument instead. No luck so far. Any insight?
Note: This attempt is the result of a research trying to print a Widget to PDF as you can check here: https://stackoverflow.com/questions/...and-python-3-5
Re: Remove the Margins of a QtextEdit or QtextDocument when printing.
Small update with something weird to me:
Code:
print("Margins: " + str(self.textReport.getContentsMargins()))
self.textReport.setContentsMargins(2, 2, 2, 2)
print("New margins: " + str(self.textReport.getContentsMargins()))
Outputs:
Quote:
Margins: (1, 1, 1, 1)
New margins: (1, 1, 1, 1)
Shouldn't it be the 2nd output 2, 2, 2, 2?
Is this a bug of Qt5 or PyQt5?