Stefano Borini
Stefano Borini

Reputation: 143765

How can I know the absolute position of the text input cursor in a QTextEdit?

QTextEdit apparently has a textCursor() method that returns a QTextCursor, but this is a Cursor to modify the document. I see no way to get the actual absolute (or relative to the widget) position of the blinking cursor in the GUI. How can I retrieve this information?

Upvotes: 0

Views: 2098

Answers (1)

SeriousHornCat
SeriousHornCat

Reputation: 46

The QTextEdit has a method called cursorRect() that returns the QRect containing the position information of the cursor.

http://qt-project.org/doc/qt-4.8/qtextedit.html#cursorRect-2

QRect QTextEdit::cursorRect ( const QTextCursor & cursor ) const
returns a rectangle (in viewport coordinates) that includes thecursor.
QRect QTextEdit::cursorRect () const
returns a rectangle (in viewport coordinates) that includes the cursor of the text edit.

QRect shall be able to provide the coordinates. http://qt-project.org/doc/qt-4.8/qrect.html

Upvotes: 3

Related Questions