I would like to execute a QMenu
object at the position of text cursor in a QPlainTextEdit
. My problem is that QTextCursor
is only define by its position in the Text (index of the character).
How can I find global position of the QTextCursor
? Should I use an other object than QTextCursor
in order to find the position of the text cursor where I want to open my QMenu
?
Thank you by advance.
If there is no selection, you can use the properties . selectionStart or . selectionEnd (with no selection they're equal). var cursorPosition = $('#myTextarea').
If you ever had a specific case where you had to retrieve the position of a caret (your cursor's position) inside an HTML input field, you can do so using the selectionStart property of an input's value.
You get the cursor position by calling GetCursorPos . This returns the cursor position relative to screen coordinates. Call ScreenToClient to map to window coordinates.
At ANSI compatible terminals, printing the sequence ESC[6n will report the cursor position to the application as (as though typed at the keyboard) ESC[n;mR , where n is the row and m is the column.
I've never tried myself, but doesn't QPlainTextEdit::cursorRect()
work? It should give you position of the cursor in viewport coordinates. You can then get the viewport using viewport()
and map the local position to global using viewport()->mapToGlobal()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With