PDA

View Full Version : Highlighting word by word



arumita
7th May 2014, 17:41
Hi :)
What i want is this : open a text file, have a pointer for words in the text, move it (the pointer) word by word (sequentially from the beginning till end of the text) , and highlight these words one by one according to the movement of the pointer ----> as a result the output will show text and the highlighting is moving word by word from the beginning of the text with some delay.
So :rolleyes: i did open text file using qtextedit .. that's it :(
my questions are:
- choosing qtextedit in this case is correct or not?? if not what should i use??
- how to use pointer for words???
- how to do the highlighting????
i'm finding here a lot of possibilities but i'm confused
Any help or advice will be greatly appreciated
thnx :o

ChrisW67
8th May 2014, 00:17
Access the QTextDocument that underlies the QTextEdit. You can then create a QTextCursor into the document and use something like:


cursor->movePosition(QTextCursor::StartOfWord, QTextCursor::MoveAnchor);
cursor->movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);

to highlight the current word, and:


cursor->movePosition(QTextCursor::NextWord, QTextCursor::MoveAnchor);
cursor->movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);

to move along a word.

arumita
10th May 2014, 10:16
Thank you so much ChrisW67 for your help,
so pointer for words done , but moving the pointer and highlighting is still not clear for me :(