Results 1 to 10 of 10

Thread: QTextDocument color

  1. #1
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default QTextDocument color

    Hey there.

    I'm using a QTextDocument to display paragraphes.
    Is there a way to set the "default" text color.

    Thanks.

  2. #2
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default Re: QTextDocument color

    Qt Code:
    1. QString style = "color: rgb(%1,%2,%3);";
    2. mTextDocument->setDefaultStyleSheet(style.arg(mColor.red()).
    3. arg(mColor.green()).
    4. arg(mColor.blue()));
    To copy to clipboard, switch view to plain text mode 

    Tried this with no success.

  3. #3
    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: QTextDocument color

    Shouldn't it be QString("color: %1;").arg(mColor.name()) ?

  4. #4
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default Re: QTextDocument color

    Should be working with rgb :/.

  5. #5
    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: QTextDocument color

    What do you do with the document afterwards? Maybe it's enough to set the color in the object (widget?) used as a container for the document?

  6. #6
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default Re: QTextDocument color

    Actually it's not set in a widget,
    I use the TextDocument for HTML strings that are displayed by my view's paint event.
    Last edited by bunjee; 15th April 2008 at 18:04.

  7. #7
    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: QTextDocument color

    Why don't you add the style definition to the html manually?

  8. #8
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default Re: QTextDocument color

    I was thinking doing so. I was just checking that nobody had a better solution.

    And beside I'm not a big fan of Html parsing .

  9. #9
    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: QTextDocument color

    You can also set a QTextFormat for each document block. Setting a pen with a colour of your choice on the painter in the paint event before painting might also help.

  10. #10
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default Re: QTextDocument color

    Unfortunately, that didn't help,

    I'm still trying to figure out how I can set a default color for a QTextDocument without erasing html tags and stuff like that.

    Changing the pen in the paint event has no effect.
    There's got to be some convenient way to do so.

Similar Threads

  1. Using a QFrame as a color selection indicator
    By KShots in forum Qt Tools
    Replies: 8
    Last Post: 14th June 2011, 23:55
  2. Change QPushButton Background Color, Qt4.3
    By Rayven in forum Qt Programming
    Replies: 5
    Last Post: 4th July 2009, 07:14
  3. How to change color of a QPushButton?
    By vishal.chauhan in forum Qt Programming
    Replies: 6
    Last Post: 5th March 2008, 13:22
  4. How to fill the grid with the color?
    By merry in forum Qt Programming
    Replies: 3
    Last Post: 18th June 2007, 11:10
  5. QTextDocument - color, font
    By kemp in forum Qt Programming
    Replies: 6
    Last Post: 24th January 2007, 13:51

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.