how can I get the word under the mouse?
(this is to get the word and show in a tooltip the help of this command, p.e.)
Thanks
how can I get the word under the mouse?
(this is to get the word and show in a tooltip the help of this command, p.e.)
Thanks
Start with looking at QTextEdit docs. According to your problem description, you need a methods which takes a QPoint. You'll find a method which gives you a QTextCursor. The next step is to dig into QTextCursor docs. Search for "word" and you'll find QTextCursor::WordUnderCursor. The rest is left as an exercise for the reader.
J-P Nurmi
I have read these helps, and I use this code in a mouseMoveEvent:Start with looking at QTextEdit docs. According to your problem description, you need a methods which takes a QPoint. You'll find a method which gives you a QTextCursor. The next step is to dig into QTextCursor docs. Search for "word" and you'll find QTextCursor::WordUnderCursor. The rest is left as an exercise for the reader.
Qt Code:
this->setToolTip(getToolTip(tc.selectedText()));To copy to clipboard, switch view to plain text mode
but this work if the cursor is on/into the word. But I want that although the cursor is in other place, only moving the mouse pointer onto the word, gets the word below the mouse pointer.
Catch QEvent::ToolTip and use QToolTip::showText().
Edit: try something like this
Qt Code:
{ { if (!cursor.selectedText().isEmpty()) else return true; } }To copy to clipboard, switch view to plain text mode
Last edited by jpn; 11th February 2008 at 13:18. Reason: updated contents
J-P Nurmi
Hi,
I know this is an older thread, but it fits. I am trying to do something similar in QT4.5.
I have a QTextEdit in which i want to show information whenever the user hovers on the text.
But i have the following problem:
- the tooltip apears almost one line below the cursor,
- when the mouse is on a blank area, the tooltip shows the last word of the line or text.
Is there any way to get the text cursor position in viewport coordinates, in order to make sure that the mouse cursor is "close" to it?
Thanks,
Eric
Bookmarks