[QScintilla] showing ToolTips dinamically

Phil Thompson phil at riverbankcomputing.com
Sat Nov 8 11:43:43 GMT 2008


On Sat, 08 Nov 2008 00:15:22 +0100, Andrea Battisti <battisti at actgate.com>
wrote:
> [...]
> 
>> > For example, a use case would be the following: when the mouse is held
>> > for a second or two over a word, then a pop-up could appear showing
>> > context-specific information on that word.
>> 
>> Here's a working example in python:
> 
> 
> Baz, Phil,
> 
> thank you very much for your replies!
> 
> 
> Just in case it could be useful to somebody, here is a simple function
> in C++ to get the string below a position (e.g. mouse cursor):
> 
> 
> QString QSciScintilla::wordAtPos( const QPoint &pos ) const
> {
> 	long closePos = SendScintilla( SCI_POSITIONFROMPOINTCLOSE, pos.x(),
> pos.y() );
> 
> 	// no close characters
> 	if ( closePos < 0 )
> 		return QString();
> 
> 	long startPos = SendScintilla( SCI_WORDSTARTPOSITION, closePos, true );
> 	long endPos = SendScintilla( SCI_WORDENDPOSITION, closePos, true );
> 	int wordLen = endPos - startPos;
> 
> 	// no word found
> 	if ( wordLen <= 0 )
> 		return QString();
> 
> 	// extract the word
> 	char *buf = new char[ wordLen + 1 ];
> 	SendScintilla( SCI_GETTEXTRANGE, startPos, endPos, buf );
> 	QString resString = convertTextS2Q( buf );
> 	delete[] buf;
>     
> 	return resString;
> }

This will be in tonight's snapshot - though I've called it wordAtPoint().

Thanks,
Phil


More information about the QScintilla mailing list