Results 1 to 2 of 2

Thread: Remove the Margins of a QtextEdit or QtextDocument when printing.

  1. #1
    Join Date
    Aug 2017
    Posts
    11
    Qt products
    Qt5
    Platforms
    Windows

    Default 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.



    This is my PyQt5 Code:

    Qt Code:
    1. setupdialog = QPrintDialog()
    2. if setupdialog.exec() == QPrintDialog.Accepted:
    3. printer = setupdialog.printer()
    4. textReport.print(printer)
    To copy to clipboard, switch view to plain text mode 
    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:
    Qt Code:
    1. printer.setPageMargins(0.1, 0.1, 0.1, 0.1, QPrinter.Millimeter) #left top right bottom
    2. printer.setFullPage(True)
    3. printer.setPageMargins(QPrinter.Millimeter)
    4. printer.setPageRect(QPrinter.Millimeter)
    5. printer.setPaperRect(QPrinter.Millimeter)
    6. printer.setPageSizeMM()
    7. printer.setResolution()
    8. printer.setPaperName()
    9. textReport.setContentsMargins(0, 0, 0, 0)
    10. QTextDocument.setIndentWidth()
    To copy to clipboard, switch view to plain text mode 
    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

  2. #2
    Join Date
    Aug 2017
    Posts
    11
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Remove the Margins of a QtextEdit or QtextDocument when printing.

    Small update with something weird to me:

    Qt Code:
    1. print("Margins: " + str(self.textReport.getContentsMargins()))
    2. self.textReport.setContentsMargins(2, 2, 2, 2)
    3. print("New margins: " + str(self.textReport.getContentsMargins()))
    To copy to clipboard, switch view to plain text mode 
    Outputs:
    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?

Similar Threads

  1. How remove margins
    By Gbx in forum Newbie
    Replies: 3
    Last Post: 22nd April 2017, 20:10
  2. QTextEdit - margins, indents within QTextEdit
    By Acamapichtli in forum Newbie
    Replies: 12
    Last Post: 9th April 2014, 18:37
  3. How to remove margins from plot?
    By P@u1 in forum Qwt
    Replies: 2
    Last Post: 27th July 2011, 15:10
  4. Remove the Margins
    By Serenity in forum Qt Programming
    Replies: 1
    Last Post: 12th August 2010, 11:33
  5. margins in QTextEdit/QPlainTextEdit
    By corrado in forum Qt Programming
    Replies: 2
    Last Post: 22nd April 2010, 10:35

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.