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?
QTextEdit.cursorRectreturns a rectangle (in viewport coordinates) that includes the cursor.You're probably imlementing autocompletion/intellisense, it which case I'd recommend using
QCompleterinstead ofQMenu. Take a look at Custom Completer Example.You can override
QTextEdit.keyPressEventor use eventFilter to capture Ctrl+Space shortcuts and callcompleter.complete(rect)to show popup.