Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QTextEdit : How to find the visible part
Harry123 last edited by
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?
Harry123 last edited by Harry123
Finally it's up to me to answer my question.
One can use
QTextEdit::cursorForPositionthat uses viewport coordinates
QTextEdit 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();
sanjay1155 last edited by
This post is deleted!