In order to extend /implement a custom widget with multiple lines (like a QTextEdit), I would need to convert widget coordinates to text position and text position to coordinates.
E.g. Mouse click on the text set the cursor position there. E.g.2 Using arrow keys will change the cursor position, which need to be drawn.
The drawing of the text is made with some line like:
painter.drawText(
textRect,
Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap |Qt::TextJustificationForced,
text());
So if the text is about 130 characters, and the cursor position is at the position (e.g.) 60.
How to get the QPoint/QPointF at which this character 60 is drawn? If the user click at the position 110x16, which caracter is at this point?
I looked the function for QFontMetrics and QPainter, also the QTextCursor class. But I did not found any solution.