Results 1 to 3 of 3

Thread: Update characters QTextCharFormat in QTextEdit

  1. #1

    Default Update characters QTextCharFormat in QTextEdit

    Hi

    I'm tring to update a caracter under the mouse pointer, like an hiperlink do when the mouse pass over it.

    My code is the following:

    Qt Code:
    1. void MyClass::mouseMoveEvent(QMouseEvent *event)
    2. {
    3. QTextCursor Cursor;
    4.  
    5. Cursor = cursorForPosition(event->pos());
    6.  
    7. if(!Cursor.isNull())
    8. {
    9. Format= Cursor.charFormat();
    10.  
    11. if(Format.isValid())
    12. {
    13. Format.setFontUnderline(true);
    14. Cursor.setCharFormat(Format);
    15. }
    16. }
    17. }
    To copy to clipboard, switch view to plain text mode 

    but nothing happen and the character is not updated. Please, note that this is only an example code, the use of setFontUnderline() is just for explain thet also if I update the character under cursor my update doesn't reflect into the text edit widget. Is there an additional function to call for force the repaint of the character after set the new property?

    Thank you

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

    Default Re: Update characters QTextCharFormat in QTextEdit

    Is your mouseMoveEvent() ever called, i.e. have you turned on setMouseTracking?
    Does the cursor returned have a selection to apply a format to?

    What is going to unset the underline?

  3. #3

    Default Re: Update characters QTextCharFormat in QTextEdit

    Hi

    Thank you for your reply.

    Yes, the mouseMoveEvent() is called, he cursor is valid and I can read correctly the properties of QTextCharFormat object (this part is not reported in the example code but it work). This mean the object returned is a valid copy of the property characters under cusor. My problem is after I changed some property as in example it seem I'm not able to update the status of the characters in object. Also if I call setCharFormat for update the status nothing change into the QTextEdit. I suppose I need to make some additional call for "force" widget repaint but, currently, I have no idea how to do...

Similar Threads

  1. Replies: 0
    Last Post: 7th June 2012, 21:58
  2. QTextEdit not display new line characters
    By aruval3 in forum Qt Programming
    Replies: 2
    Last Post: 30th November 2011, 04:46
  3. QTextEdit and Chinese characters on a Mac
    By jupi32000 in forum Qt Programming
    Replies: 0
    Last Post: 17th February 2010, 01:02
  4. read an xml file with Asian characters in QTextEdit
    By Boris Liao in forum Qt Programming
    Replies: 1
    Last Post: 23rd January 2010, 22:56
  5. QTextCharFormat::setAnchor
    By ccf_h in forum Qt Programming
    Replies: 0
    Last Post: 30th November 2008, 17:01

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.