Solved QTextEdit : How to find the visible part
-
The problem is how to find out exactly which part of the QTextEdit is currently visible, meaning starting with the first block#/line#/character# that is visible and ending with the last block#/line#/character# that is still visible.
A solution that returns the positions of these characters inside the QTextEdit is good enough, as these can be converted to block#/line#/character#.
I have seen one very partial solution (here) that involved arithmetic between the viewport and the bounding rectangles of blocks. But beside its complexity, it only finds block-numbers.
Can anybody answer this question?
-
Finally it's up to me to answer my question.
One can use
QTextEdit::cursorForPosition
that uses viewport coordinatesQTextEdit textEdit; int start_pos = textEdit.cursorForPosition(QPoint(0, 0)).position(); QPoint bottom_right(textEdit.viewport()->width() - 1, textEdit.viewport()->height() - 1); int end_pos = textEdit.cursorForPosition(bottom_right).position();
-
This post is deleted!