Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
[SOLVED] QPlainTextEdit Print question
Pt_develop last edited by
DUH. I mentally read height instead of y in line 34 in the code below. There is no problem and the code snippet will print out the text and is easily modified to print headers and footers.
I'm a little embarrassed to ask this question but here goes. Some time ago I wrote some code to print out headers and footers for a plain text editor. Now I want to expand this to include line numbers but I forgot why some things in my original code works and I need to rediscover why it works (I understood it when I first wrote it, I think).
One line which has nothing to do with headers or footers in particular stumps me. A simplified code snippet illustrates the problem:
@// current printer supplied as an argument
// set the page drawing area (smaller than the entire page area because of margins)
// find the content drawing area size for one page
// set the document page size
// set up the bounding rectangles
// translate the painter orgin to the drawing area
// initialize the loop rectangle
// loop until currentRect no longer intersects with contentRect
// restore/save the painter and draw the current contents page
painter.translate(0,-currentRect.y()); // ???
// adjust y printer coordinate to print the next page by translating currentRect to the next page currentRect.translate(0,currentRect.height()); // advance to a new page if there is anything left to print if(currentRect.intersects(contentRect))currentPrinter->newPage();
}// end currentRect while loop
The conceptual problem I have is line 34 in the above code.
@ painter.translate(0,-currentRect.y()); // ??? @
Looking at other code snippets such as:
it appears that this line is unnecessary.
Indeed if eliminate this line of code then the first page of the document is printed correctly. Unfortunately all subsequent pages are not printed correctly. If I include this line of code then every page is printed correctly.
My question is why is this line of code necessary? In fact how does the first page get printed correctly when this line of code is included?
Any help will be appreciated (FYI: I'm using 4.8 on windows 7).