Glyph painting is a very hard job in general. Ultimately, that is probably a Qt bug, or type bug (glyph definition). You have to remember, that some letters are allowed to go beyond their registered space (take a 'y' for example, in some types, and especially in handwriting, it often even obscures other letters), others are allowed to join, etc.
I had that problem in my code, too, I've added the aligning as above + adjusted the margins by hand. It seems to be working well, even during scaling, and on different operating systems.