Select a word by cursor and get its position in Qt/C++ -
i have small qt/c++ application qtextedit
uploads text. want able select separate word cursor , position in text.
for example, in following sentence: "it sunny day". if select word 'sunny', int
4, placed @ 4th position in sentence.
how can achieve that?
you'll have :
get field's text
qstring
usingqtextedit::text()
methoduse
qtextedit.textcursor()->selectionend()
know selection ends.use
qstring::mid
substring 0 end of selectionuse
qstring::count
know how many spaces contains. give access word's position.
something like:
textedit.text().mid( 0, textedit.textcursor()->selectionend() ).count( ' ' )+1;
hope helps. that's minimal, you'll want deal partial word selection or others relevant corner case.
Comments
Post a Comment