Results 1 to 4 of 4

Thread: Why painter->setPen() doesn't work with QTextDocument?

  1. #1
    Join Date
    Aug 2007
    Posts
    244
    Thanks
    42
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Why painter->setPen() doesn't work with QTextDocument?

    If I have this code:

    Qt Code:
    1. ...
    2. QPainter *painter = new QPainter(this);
    3. painter->setPen(Qt::white);
    4. QAbstractTextDocumentLayout::PaintContext context;
    5. doc.setTextWidth(220);
    6. doc.setHtml(text);
    7. doc.documentLayout()->draw(painter, context);
    To copy to clipboard, switch view to plain text mode 

    the text is drawn in black instead of white? Only if i write:

    Qt Code:
    1. doc.setHtml("<font color=\"white\">" + text + "</font>");
    To copy to clipboard, switch view to plain text mode 

    it works.

    Regards
    Giuseppe CalÃ

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Why painter->setPen() doesn't work with QTextDocument?

    QTextFormat and its descendants are resonsible for text formatting in QTextDocument, not the painter.
    Last edited by jacek; 9th November 2007 at 16:51. Reason: it should be QTextFormat, not QTextDocument

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

    jiveaxe (9th November 2007)

  4. #3
    Join Date
    Aug 2007
    Posts
    244
    Thanks
    42
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Why painter->setPen() doesn't work with QTextDocument?

    Ok, understood.

    Thanks
    Giuseppe CalÃ

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Why painter->setPen() doesn't work with QTextDocument?

    Of course it's the QTextFormat what is responsible for formatting, not QTextDocument. I don't know why I wrote QTextDocument.

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.