Results 1 to 6 of 6

Thread: How to get current word in Qtextedit

  1. #1
    Join Date
    Oct 2008
    Location
    Thodupuzha, a small town in kerala
    Posts
    31
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default How to get current word in Qtextedit

    Hi masters

    Can anyone help me to find the on which word the cursor is now on QTextEdit. I couldnt even find the current character. I tried to use charAt() function but but I dont know how to get current cursor position(QPoint variable.).Hoping for any help.

    Thanking you
    Jayanth.S

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to get current word in Qtextedit

    try this
    Qt Code:
    1. ...
    2. QTextCursor tc = m_textEdit->textCursor();
    3. tc.select(QTextCursor::WordUnderCursor);
    4. QString word = tc.selectedText();
    5. ...
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Oct 2008
    Location
    Thodupuzha, a small town in kerala
    Posts
    31
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: How to get current word in Qtextedit

    Thanks for the quick reply...But When I use that code I am getting errors


    error: variable ‘QTextCursor tc’ has initializer but incomplete type
    error: ‘QTextCursor* QTextEdit::textCursor() const’ is protected
    error: incomplete type ‘QTextCursor’ used in nested name specifier

    I tried to find an header file for QTextCursor but failed ... What am I missing...

  4. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to get current word in Qtextedit

    what version of Qt do you use?
    looks like Qt 3, but in you info you use Qt 4
    so, my code for Qt 4.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  5. #5
    Join Date
    Oct 2008
    Location
    Thodupuzha, a small town in kerala
    Posts
    31
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: How to get current word in Qtextedit

    I am using QT 3.3... Is there any other methods , which work on QT 3.3 also...Atleast if I can get the current character then I can parse out the word...Help me...

    Jayanth.S

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to get current word in Qtextedit

    Use QTextEdit::getCursorPosition() to get the index of the paragraph where the cursor is positioned and then use QTextEdit::text() to get the text of that paragraph. Then you can find the word the cursor is at using the position in the paragraph retrieved with the first call.

    BTW. You might want to update your forum profile if you use Qt3. Currently it says you are using Qt4 only.
    Last edited by wysota; 6th April 2009 at 09:02.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 2
    Last Post: 20th February 2012, 21:58
  2. QTextEdit: get word under the mouse pointer?
    By zorro68 in forum Qt Programming
    Replies: 4
    Last Post: 13th November 2009, 15:42
  3. Distributing QT application for Mac OS
    By mb0 in forum Qt Programming
    Replies: 1
    Last Post: 31st May 2007, 18:59
  4. Replies: 15
    Last Post: 21st April 2007, 17:46
  5. Current char in QTextEdit
    By jlbrd in forum Qt Programming
    Replies: 1
    Last Post: 12th August 2006, 09:30

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.