PDA

View Full Version : Display tooltip for a selected word in QTextEdit



qtnewbie6019
24th June 2013, 07:59
I'm writing a simple text editor using Python 2.7, pyqt library. I basically want to display the meaning of a word when the user selects the word in the text editor.

So far I can detect the word under the cursor, look it up in my dictionary and return the meaning (using a print statement) so I know I can get the guts to work.

My trouble is displaying the meaning of the word in a tooltip that doesn't dissapear in less than 2 miliseconds. So far I have been using this:

QtGui.QToolTip.showText(QtGui.QCursor.pos(), tool_tip_text)

Ideally want to show the meaning just over where the selection was made, so far this displays the tooltip so quickly that I can't even read the meaning of the word under the cursor. It just pops up and dissapears almost immediately. Can anyone share how to make the tooltip remain visible for at least 5 seconds, or until the user de-selects the word.

I am not using the QHELPEVENT (not even quite sure how the helpevent is triggered) I am just calling my lookup_word_in_dictionary() function when a word has been selected.

Any samples are much appreciated.