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.
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.
Check the implementation of drawCursor(), maybe it does some painter transformations prior to drawing the cursor. Maybe this will fix the difference between your line and drawCursor(). If the line itself is at a wrong position then I'd assume your earlier calculations don't take some aspect into consideration. Check the source code for QLineEdit again and see if you didn't miss something.
pfff... finally, I fixed it. I had to reimplement the QLineEdit::mousePressEvent() and QLineEdit::mouseMoveEvent() methods to calculate the cursor position and call setCursorPosition().
Could you post your code for the mouse events?
Send image for us.
Bookmarks