Closed bibimbop closed 11 years ago
Yeah, if I knew how to do it, I'd a did it. Something in QPlainTextEdit or QTextBlock or somewhere. I'll look into it soon.
QTextEdit.cursorRect() returns the viewport coordinates of the cursor's selected text as a QRect QTextEdit inherits from QAbstractScrollArea QTextEdit (via QAbstractScrollArea) .viewport returns the viewport (a QWidget) thus editWidget.viewport().size().height() returns the height of the viewport --in what units? Same units as the cursorRect anyway -- so editWidget.cursorRect().x() is the top edge of the cursor text -- this can be related to the viewport height/2 -- if greater, need to scroll down to bring text up
QAbstractScrollArea.verticalScrollBar() returns the QScrollBar for the vertical. (Will there be one when the doc is less than a page? prob. returns null: check) If there is no scrollbar -- or if it is already at its maximum (QScrollBar.maximum()) -- do nothing. QScrollBar.value() returns the absolute value of the scrollbar (in what units? pixels? lines?) QScrollBar.setValue( previous value + adjustment ) should move the document...
Major drawback: the cursorRect() does not give the size of the selected text, but only the size and position of the cursor (insertion point) itself. So its height is always 11 (if the font size is 11) and you cannot tell what the height of the complete selectioin is.
Also not good: the position is of the logical cursor position, which on a large multiline selection, may well be the END of the selection not the beginning.
Additional problem: the scrollBar.value is in logical line units, not pixel units like the cursorRect is.
Commit 69c28cc
For some kind of searches, it's useful to have the line containing the text found to always be on the same location on the edit window (usually at the center of it). That way the searched item doesn't jump all over the place in the window when clicking on next/prior/... It's easier on the eyes.
It's how guiguts and many editors work. This also could be an option.