Results 1 to 7 of 7

Thread: QTextDocument - color, font

  1. #1
    Join Date
    Aug 2006
    Posts
    77
    Thanks
    14
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QTextDocument - color, font

    Hi!

    I have a syntax highlighted QTextEdit. Is there a way to get the information: font,color..
    out of the QTextDocument for each character.
    So I want to get this information out of the editor->document ().

    Is that possible.

    Thanks.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QTextDocument - color, font

    Are you using QSyntaxHighlighter?
    you can query the current formatting and user data using the format()
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    kemp (24th January 2007)

  4. #3
    Join Date
    Aug 2006
    Posts
    77
    Thanks
    14
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTextDocument - color, font

    Thank you for your answer. Does that mean that I still need QTextEdit to aces the highlighter,
    or is there a way to do that through the document alone?

  5. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QTextDocument - color, font

    Could you please explain the task? For what do you actually need all the colors?

    For syntax highlighting purpose, QSyntaxHighlighter can do those pretty handy; format() & setFormat().

    If you really need to manually extract the same information, I think you should first retrieve the corresponding QTextBlock, then construct a QTextCursor for it, move it to the correct position and then ask for it's format.
    J-P Nurmi

  6. #5
    Join Date
    Aug 2006
    Posts
    77
    Thanks
    14
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTextDocument - color, font

    I have a print preview. I get the document and in paintevent I iterate through the textblocks and through text in each textblock. Now I want to make everything in color like there is in texteditor that i highlighted with the syntaxhighlighter.

  7. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QTextDocument - color, font

    Maybe you could get away with calling QTextDocument::drawContents() with a painter having a suitable scaling? That's just an idea, I don't know if it would work as desired..
    J-P Nurmi

  8. #7
    Join Date
    Aug 2006
    Posts
    77
    Thanks
    14
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTextDocument - color, font

    Thanks for your help.

Similar Threads

  1. From QPrinter to QTextDocument
    By kemp in forum Qt Programming
    Replies: 1
    Last Post: 24th November 2006, 15:44
  2. QTextDocument resources
    By xgoan in forum Qt Programming
    Replies: 1
    Last Post: 19th November 2006, 10:18
  3. Replies: 0
    Last Post: 28th June 2006, 20:49
  4. How to convert QTextDocument to PNG file?
    By Gonzalez in forum Qt Programming
    Replies: 1
    Last Post: 2nd February 2006, 14:46

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.