... no clue...?
... no clue...?
My guess is that there is a mixup of coordinate systems... QTextEdit uses viewport coordinates in some places and "normal" widget coordinates in other. If you are not careful enough about which coordinates you get and which you should use for each task (e.g. painting, hit detection, ...) you encounter problems as this one. How do you initialize your painter? Do you invoke any of its coordinate related functions? Do you make use of QAbstractScrollArea viewport margins?
Current Qt projects : QCodeEdit, RotiDeCode
I posted the code since it answers a lot of things:
1) the painter is initialized to the viewport.
2) I do not apply any transformations to the painter (is this what you mean?)
3) I used the viewport margins, but I am not sure it is the cause, since (IMHO) if it was, I would see a constant shift of the position. The shift is relative to the font size on this example.
Proposed fix (not perfect but way better than what you achieved previously) :
Qt Code:
p.fillRect( r.x() + r.width() / 2, r.y(), charWidth, r.height(), matchBracesColor );To copy to clipboard, switch view to plain text mode
It falls down to replacing charWidth by r.width() / 2. This is because :
- charWidth depends on the "matched" char while cursor is placed between characters bounds...
- cursor is in the middle of the rect returned by cursorRect
Current Qt projects : QCodeEdit, RotiDeCode
Bookmarks