Results 1 to 2 of 2

Thread: QTextDocument + style CSS does not work

  1. #1
    Join Date
    May 2008
    Posts
    276
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QTextDocument + style CSS does not work

    I have an html string which stores some tables.
    I would change the style of the tables by means of css style:

    border: solid 1px

    So, I used immediately after the constructor of QTextDocument

    Qt Code:
    1. textdocument->setDefaultStyleSheet(cssTable())
    To copy to clipboard, switch view to plain text mode 

    where cssTable() returns

    Qt Code:
    1. QString OutReport::cssTable()
    2. {
    3. a = "<style type=\"text/css\">";
    4. a += "table.sample {border-width: 10px;border-spacing: ;border-style: outset; border-color: gray; border-collapse: collapse; background-color: white; }";
    5. a +=" table.sample th { border-width: 1px; padding: 1px; border-style: inset; border-color: gray; background-color: white; -moz-border-radius: ; }";
    6. a += "table.sample td { border-width: 1px; padding: 1px; border-style: inset; border-color: gray; background-color: white; -moz-border-radius: ; }";
    7. a+="</style>";
    8. return a;
    9. }
    To copy to clipboard, switch view to plain text mode 

    Then, when I wanna print a table in the text document,

    Qt Code:
    1. totale = " <table class=\"sample\"><tbody><tr><td>"+ QObject::tr("Totale annuo") +"</td><td></td><td>" + t + "</tr>";
    2. totale +="<tr><td>" + QObject::tr("Rendimento") + "</td><td></td><td>" + t2 +"</tr></table>";
    3. ...
    4. textdocument->setHtml(totale);
    To copy to clipboard, switch view to plain text mode 

    But when I print with textdocument->drawContents(&p,printer->paperRect()) (p is a QPainter(printer)) nothing changes.
    Why?

  2. #2
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextDocument + style CSS does not work

    I couldn't get this to work, either. Just prepend your css-stuff to your html code. Works for me.

    textdocument->setHtml(cssTable()+totale);

    HIH

    Johannes

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

    giusepped (23rd June 2010)

Similar Threads

  1. "Proxy Style" does not work!
    By Dimon in forum Qt Programming
    Replies: 3
    Last Post: 18th February 2010, 11:20
  2. Problems with Gradient style used through Style sheet on ARM platform
    By puneet.narsapur in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 25th January 2010, 12:48
  3. QT's style sheet does not work properly on Mac OS X
    By sanjayshelke in forum Qt Programming
    Replies: 1
    Last Post: 10th December 2009, 10:50
  4. Why painter->setPen() doesn't work with QTextDocument?
    By jiveaxe in forum Qt Programming
    Replies: 3
    Last Post: 9th November 2007, 16:53
  5. Replies: 1
    Last Post: 7th February 2007, 00:12

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.