Results 1 to 3 of 3

Thread: QTextDocument: borders style for particular cells

  1. #1
    Join Date
    Nov 2012
    Posts
    8
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default QTextDocument: borders style for particular cells

    Hi! First of all - sorry for my English, I'm trying to do my best.

    I want to make the report (and print it) with quite complex table. Last row of my table must be painted in part, i.e. part of cells shouldn't be painted. Something like that:

    qqq.JPG

    In HTML terms it looks like that (very garbage code, just explain my idea):

    Qt Code:
    1. <table cellspacing=0 style="border-collapse: collapse">
    2. <tr><td style='border: 1px solid black'>1</td>
    3. <td style='border: 1px solid black'>2</td>
    4. <td style='border: 1px solid black'>3</td></tr>
    5. <tr><td style='border: 1px solid black'>One</td>
    6. <td style='border: 1px solid black'>Two</td>
    7. <td style='border: 1px solid black'>Three</td></tr>
    8. <tr><td style='border-width: 1 0 0; border-style: solid; border-color: black'></td>
    9. <td style='border-width: 1 0 0; border-style: solid; border-color: black'></td>
    10. <td style='border: 1px solid black'>Finish</td></tr>
    11. </table>
    To copy to clipboard, switch view to plain text mode 

    I'm using QTextDocument for my task. But neither setHtml() or QTextCursor (rather QTextTable) doesn't support styles for particular tables, only for the whole table! My attemps (using html, QTextCursor gives about the same result):
    1) if set border style to the whole table, we get proper borders (a bit of thick, but that's other question):
    Qt Code:
    1. QString html = "<html><body>";
    2. html += "<table cellspacing=0 cellpadding = 2 style='border-width: 1px; border-style: solid; border-color: #000000'>";
    3. html += "<tr>";
    4. html += "<td>1</td>";
    5. html += "<td>2</td>";
    6. html += "<td>3</td>";
    7. html += "</tr>";
    8. html += "<tr>";
    9. html += "<td>One</td>";
    10. html += "<td>Two</td>";
    11. html += "<td>Three</td>";
    12. html += "</tr>";
    13. html += "<tr>";
    14. html += "<td></td>";
    15. html += "<td></td>";
    16. html += "<td>Finish</td>";
    17. html += "</tr>";
    18. html += "</table></body></html>";
    19.  
    20. page->setHtml(html);
    To copy to clipboard, switch view to plain text mode 
    qq1.JPG

    2) If try to make the same as with HTML (i.e. set border style for every cell), we get no borders at all.
    Qt Code:
    1. QString html = "<html><body>";
    2. html += "<table cellspacing=0 cellpadding=2'>";
    3. html += "<tr>";
    4. html += "<td style='border-width: 1px; border-style: solid; border-color: #000000'>1</td>";
    5. html += "<td style='border-width: 1px; border-style: solid; border-color: #000000'>2</td>";
    6. html += "<td style='border-width: 1px; border-style: solid; border-color: #000000'>3</td>";
    7. html += "</tr>";
    8. html += "<tr>";
    9. html += "<td style='border-width: 1px; border-style: solid; border-color: #000000'>One</td>";
    10. html += "<td style='border-width: 1px; border-style: solid; border-color: #000000'>Two</td>";
    11. html += "<td style='border-width: 1px; border-style: solid; border-color: #000000'>Three</td>";
    12. html += "</tr>";
    13. html += "<tr>";
    14. html += "<td style='border-style: none;'></td>";
    15. html += "<td style='border-style: none;'></td>";
    16. html += "<td style='border-width: 1px; border-style: solid; border-color: #000000'>Finish</td>";
    17. html += "</tr>";
    18. html += "</table></body></html>";
    19.  
    20. page->setHtml(html);
    To copy to clipboard, switch view to plain text mode 
    qq2.JPG

    But I need the table at the beginning of my post. Any suggestions? Only crazy option comes to mint: stupidly draw each line with QPainter...

  2. #2
    Join Date
    Jun 2012
    Posts
    173
    Thanks
    48
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextDocument: borders style for particular cells

    Only crazy option comes to mint: stupidly draw each line with QPainter...
    here is another crazy idea draw a white rect on the area you do want to show :P

  3. #3
    Join Date
    Nov 2012
    Posts
    8
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTextDocument: borders style for particular cells

    Quote Originally Posted by jesse_mark View Post
    here is another crazy idea draw a white rect on the area you do want to show :P
    Yes, an option too On the another forum, someone suggested me to use QWebView. I think that's not bad idea, but I have a print problems. But that is different chapter, so I'll better create one more topic...

Similar Threads

  1. Replies: 1
    Last Post: 22nd September 2011, 07:33
  2. widget borders v4.2
    By dacrawler in forum Newbie
    Replies: 0
    Last Post: 24th January 2011, 20:08
  3. QGroupBox borders
    By onurozcelik in forum Qt Programming
    Replies: 0
    Last Post: 27th August 2010, 07:24
  4. QTextDocument + style CSS does not work
    By giusepped in forum Qt Programming
    Replies: 1
    Last Post: 18th June 2010, 16:40
  5. Groupbox has no borders ?
    By vieraci in forum Qt Programming
    Replies: 12
    Last Post: 30th April 2009, 13: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.