[QScintilla] showing ToolTips dinamically

Andrea Battisti battisti at actgate.com
Fri Nov 7 23:15:22 GMT 2008


[...]

> > 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;
}


Best Regards,

-- 
Andrea Battisti
Applied Coherent Technology Corp.



More information about the QScintilla mailing list