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 :

  1. get field's text qstring using qtextedit::text() method

  2. use qtextedit.textcursor()->selectionend() know selection ends.

  3. use qstring::mid substring 0 end of selection

  4. use 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

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -