If you uncomment the last commented-out line, the painter draws a vertical line where the cursor should go. That's much more accurate than what the QTextLayout::draw() renders, but it's still off. Somehow there is a miscalculation.