PDA

View Full Version : Is there a way to get text from under the mouse cursor?



squirrel
11th July 2009, 12:04
I want to make a pop-up tool that gets the character from under the mouse cursor and a number of consequent characters. I want to use them to display the translation of this word/phrase using a dictionary. Hopefully I want to be able to parse everything in a Qt application, but if it's not possible, parsing text in WebKit would be enough.

I googled and asked on IRC, and the only thing i've got is that someone recommends using the accessibility interface, but i just don't know which part of it I can apply. The other ways include marking each character in the WebKint and using Javascript to invoke events.

So, is there a clean and tidy method of retrieving text from under the mouse cursor? Thanks in advance.

jgrauman
12th July 2009, 01:39
If using a QTextEdit, QTextEdit::cursorForPosition() should help. Pass it the mouse position and then use a QTextCursor to select and get the word.

-Josh