QTextCursor::WordUnderCursor
Hi,
I've got some weird problems with the QTextCursor::WordUnderCursor method.
Suposed I'm on a line with the following text : "link,"
then QTextCursor::WordUnderCursor returns me "link" only.
I supose it doesn't take into account some chars like opening braces, comas, etc. by default, but how can I get those chars too ?
Thanks.
Re: QTextCursor::WordUnderCursor
You can fetch the position of the cursor and then access the text block at that position and process the block the way you want.
Re: QTextCursor::WordUnderCursor
Thanks,
I solved it like this (Python code, sorry) :
Code:
oldpos = my_cursor.position()
# selects the word under the cursor
# where the selction starts
newpos = my_cursor.selectionStart()
# select from new_pos to old_pos (order is important)
my_cursor.
setPosition(newpos, QtGui.
QTextCursor.
MoveAnchor)my_cursor.
setPosition(oldpos, QtGui.
QTextCursor.
KeepAnchor)self.editor.setTextCursor(my_cursor)
SearchedText = my_cursor.selectedText()