Results 1 to 8 of 8

Thread: Get Character

  1. #1
    Join Date
    May 2009
    Posts
    94
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Get Character

    How can i get the next and previous character content from cursor posion in a QTextEdit?

  2. #2
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Get Character

    try
    QTextCursor :: position ()

  3. #3
    Join Date
    May 2009
    Posts
    94
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Post Re: Get Character

    Quote Originally Posted by yogeshgokul View Post
    try
    QTextCursor :: position ()
    it will return the position.But i want the what is the next and previous character content not the position

  4. #4
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Get Character

    Quote Originally Posted by bismitapadhy View Post
    it will return the position.But i want the what is the next and previous character content not the position
    Should be damm easy.
    Qt Code:
    1. textEdit->toPlainText().at(position-1);
    2. textEdit->toPlainText().at(position+1);
    To copy to clipboard, switch view to plain text mode 
    Last edited by yogeshgokul; 15th July 2009 at 11:14.

  5. The following user says thank you to yogeshgokul for this useful post:

    wagmare (15th July 2009)

  6. #5
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Get Character

    after selecting the character or by default position ..?
    "Behind every great fortune lies a crime" - Balzac

  7. #6
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Get Character

    Quote Originally Posted by wagmare View Post
    after selecting the character or by default position ..?

  8. #7
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Get Character

    Quote Originally Posted by yogeshgokul View Post
    but how can we get the char the QTextCursor currently positioned ..
    ex:
    hell|o world

    think "|" as cursor position .. it is in middle of "l" and "o" .. so how can i get that two char or either of it ...

    the position is dynamic at run time .. and the position is not hard coded value ..

    any way to implement ..

    and u answered it .. thank you very much ...
    "Behind every great fortune lies a crime" - Balzac

  9. #8
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Get Character

    Quote Originally Posted by wagmare View Post
    but how can we get the char the QTextCursor currently positioned ..
    ex:
    hell|o world

    think "|" as cursor position .. it is in middle of "l" and "o" .. so how can i get that two char or either of it ...

    the position is dynamic at run time .. and the position is not hard coded value ..

    any way to implement ..

    Qt Code:
    1. int pos = TextEdit->textCursor().position();
    2. QChar cPrev = TextEdit->toPlainText().at(pos);
    3. QChar cNext = TextEdit->toPlainText().at(pos+1);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Character by Character (Unicode?) File Reading
    By mclark in forum Qt Programming
    Replies: 4
    Last Post: 22nd April 2009, 15:28
  2. How to read QStringList character by character
    By iamjayanth in forum Qt Programming
    Replies: 4
    Last Post: 3rd April 2009, 11:25
  3. Getting some unusual character
    By Abc in forum Qt Programming
    Replies: 2
    Last Post: 21st August 2008, 06:28
  4. Special Character Handling
    By Kubil in forum Qt Programming
    Replies: 1
    Last Post: 22nd June 2008, 22:58
  5. Character from argument disappears
    By Pepe in forum Qt Programming
    Replies: 13
    Last Post: 19th June 2007, 23:48

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.