Issue
I have a QTextEditor which I would like to open a menu for user to choose when he press Ctrl+Space. I was able to capture the key events and create the menu and trigger it.
My problem is to open the menu on the text cursor position. How do i get the QPoint of the textcursor and not the mouse position?
Solution
QTextEdit.cursorRect
returns a rectangle (in viewport coordinates) that includes the cursor.
You're probably imlementing autocompletion/intellisense, it which case I'd recommend using QCompleter
instead of QMenu
. Take a look at Custom Completer Example.
You can override QTextEdit.keyPressEvent
or use eventFilter to capture Ctrl+Space shortcuts and call completer.complete(rect)
to show popup.
Answered By - mugiseyebrows
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.