Search code examples
qtqtextdocument

QTextDocument's print size changes when it is set as a document of QTextEdit


i faced very interesting problem (at least for me). When I do not set a QTextDocument as a document of QTextEdit with QTextEdit's setDocument method it is shown very small in previews and pdfs like in the image, only occupies very small place of the page with whole data and there are no page margins :

image http://imgim.com/small2.png

However, when I set it as a document of an arbitrary QTextEdit it is suprisingly shown normal in the page and page margins are adjusted (i.e. whole data is shown with 3 pages as normal)

QTextEdit* displayAreaxd = new QTextEdit;
displayAreaxd->setDocument(mainDocument);

This two lines of code changes all appearance in previews and pdf files when I use QTextDocument.print. and displayAreaxd is not even used after and mainDocument is a QTextDocument that is a private member of my class. So I wonder what may cause this I produce previews like :

QPrinter printer(QPrinter::HighResolution);
printer.setPaperSize(QPrinter::A4);
QPrintPreviewDialog preview(&printer, this);
connect(&preview, SIGNAL(paintRequested(QPrinter*)), SLOT(preview(QPrinter*)));
preview.exec();

my preview function is basicly where printer is coming from upper method :

mainDocument->print(printer);

my mainDocument is created and initialized like :

QPrinter printer(QPrinter::HighResolution);
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setPaperSize(QPrinter::A4);
mainDocument = new QTextDocument;
mainDocument->setPageSize(printer.pageRect().size());

After that I do some drawings with normal fonts and normal image size according to a4 page but it appears like in the image when i do not set my document to a document of an arbitrary qtextedit

Edit: When I added the code :

QFont docFont = QFont();
docFont.setPointSize(150);
mainDocument->setDefaultFont(docFont);

The text appears big, but I worry about if it can change font size with different resolutions or platforms, still I dont understand how point size changes when I set my document as a document of a text edit.


Solution

  • when I set document as a document of text edit document's width changes (decreases). because of this, present fonts look bigger in this pixel options. When I set my document's size to 9117*10530 this fonts looks smaller because their point size is small, when I set document as a document of text edit it's width decreases to 633 so with present point size of fonts they look normal. So the text edit changes document's layout and width when setDocument is called.