Important: Please read the Qt Code of Conduct -

Display problems when printing QTextEdit

  • Hey,

    Im sure this is going to be an easy fix by some function or something I just over looked or am not aware of yet but I can't get my QTextEdit to print right.

    When I use this code:
    QTextDocument *document = prevScreen->document();

    QPrinter printer;
    printer.setPageMargins(0.0, 0.0, 0.0, 0.0, QPrinter::Millimeter);
    QPrintDialog *dialog = new QPrintDialog(&printer, prevScreen);
    dialog->setWindowTitle(tr("Print First List"));
    if (dialog->exec() == QDialog::Accepted)


    it seems to have the document placed correctly but there is a boarder or something that is cutting it off so the 1st two characters on the left of everyline and last 2 on the right are cut off.. I cant figure out what is causing this, I've tried changing every margin option I can think of but it wont work.
    Does anyone have any ideas on how to solve this?

  • Do you check if your printer can print with such margins (0 mm)?

  • Are we talking about the normal ~4-5mm margins of printers? No printer can print borderless (in professional setups, they do it by cutting the borders after printing).

  • DKvita no I haven't how would I do that? (sorry this is my 1st program I'm making print out)

    DerManu, no its a little bigger the way the document I need this to look like is printed out in word right now now has a 5-6mm border and I have my program with the QTextEdit appearing on my laptop about right. But when I pulled it up on another computer with a much larger screen the QTextEdit was much bigger and it printed off, a different printer than the 2 I've previously tested, with a much larger margin/border of about an inch and didnt cut anything off..

    Because of this I now think part of the poblem as to do with the layout of my QWidget and QTextEdit as the central widget. I want it to look like MS Word with the borders on the side of the page and if possible adjust when the screen size is changed like Word too. Is there a way to do this and maybe that would help with the printing?

    Let me know if I didnt make much sense because using the larger screen and it looking/printing different really threw me off so I'm a little confused right now

Log in to reply