Hello,

I have programmed a simple code editor, which uses the QSyntaxHighlighter.
And now i have a problem with my print method.

I had to implement a new one since I need to print a header and footer on each page and I also need to print the corresponding line numbers besides the text.

After much experimentation I have almost reached my "goal".

First i get the pageRect from the given QPrinter and calculate the size for the header, footer and line numbers from which i then get the actual draw area for the document.
Then I break down the QTextDocument into its QTextBlocks in order to iterate over them within the printing process. (using a while(block.isValid())... loop)

Within the loop i break down the blocks into QTextLayouts (for the case that a block has one or more linebraks) This is also important in order to find the proper horizontal position for the line number and for the case that a block needs to be broken up between page breaks.

My current problem shows its (ugly) face after a page break where the textLayout.draw(...) method decides to ignore the horizontal position the first line and draw a few pixels off target, invading the space for the next line.
This only occurs in the first line of pages 2 and up. Page 1 is printed properly.

Can anyone give me a hint why the draw Method would be ignoring the QPoint given to it?
I use the same horizontal offset when drawing the line number which is placed properly in the page.

Thank you for reading and maybe helping

Eric