Results 1 to 3 of 3

Thread: Highlighting word by word

  1. #1
    Join Date
    May 2014
    Posts
    8
    Thanks
    4
    Qt products
    Qt5
    Platforms
    Unix/X11

    Question Highlighting word by word

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

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,734
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Highlighting word by word

    Access the QTextDocument that underlies the QTextEdit. You can then create a QTextCursor into the document and use something like:
    Qt Code:
    1. cursor->movePosition(QTextCursor::StartOfWord, QTextCursor::MoveAnchor);
    2. cursor->movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
    To copy to clipboard, switch view to plain text mode 
    to highlight the current word, and:
    Qt Code:
    1. cursor->movePosition(QTextCursor::NextWord, QTextCursor::MoveAnchor);
    2. cursor->movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
    To copy to clipboard, switch view to plain text mode 
    to move along a word.

  3. #3
    Join Date
    May 2014
    Posts
    8
    Thanks
    4
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Highlighting word by word

    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

Similar Threads

  1. how to get the word when i highlight a word with mouse?
    By saleh.hi.62 in forum Qt Programming
    Replies: 0
    Last Post: 4th July 2010, 08:24
  2. word wrap
    By deeee in forum Qt Programming
    Replies: 3
    Last Post: 26th May 2010, 19:55
  3. MS Word file
    By Arpan in forum Qt Programming
    Replies: 1
    Last Post: 30th July 2008, 20:26
  4. Two Word QRegExp Help
    By mabeeh in forum Qt Programming
    Replies: 3
    Last Post: 13th May 2008, 14:29
  5. Word wrapping
    By bruccutler in forum Qt Programming
    Replies: 4
    Last Post: 26th February 2007, 16:33

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.