Results 1 to 1 of 1

Thread: QTextDocument vs QWebView

  1. #1
    Join Date
    Mar 2013
    Posts
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTextDocument vs QWebView

    Hi all!
    Big picture:
    I have custom widget: QListView with custom delegate which renders html table using QTextDocument on each row. I have requirement to align float numbers (in last column).
    That means all float separators should be on the same position. The trick I did was using 2 inline divs which contains separated number:
    Qt Code:
    1. <style type="text/css">
    2. div { float:left;display:inline-block;width:50%; }
    3. div.left { text-align: left; }
    4. div.right { text-align: right; }
    5. </style>
    6. <table width=100% border=1>
    7. <tr><td width=33%>2</td><td width=34%>2</td><td width=33% ><div class="right">3</div><div class="left">.6</div></td></tr>
    8. </table>
    To copy to clipboard, switch view to plain text mode 
    That works fine both in browser and QWebView. The problem is QTextDocument, where layout is broken. Where's the problem and how can I fix it? Is there some CSS limitation on QTextDocument?

    Here's my PyQt code:
    Qt Code:
    1. #!/usr/bin/env python3
    2. import sys
    3. from PyQt4.QtCore import *
    4. from PyQt4.QtGui import *
    5. from PyQt4.QtWebKit import *
    6.  
    7. html=\
    8. '''
    9. <style type="text/css">
    10. div { float:left;display:inline-block;width:50%; }
    11. div.left { text-align: left; }
    12. div.right { text-align: right; }
    13. </style>
    14. <table width=100% border=1>
    15. <tr><td width=33%>2</td><td width=34%>2</td><td width=33% ><div class="right">3</div><div class="left">.6</div></td></tr>
    16. </table>
    17. '''
    18.  
    19. app = QApplication(sys.argv)
    20.  
    21. dlg = QDialog()
    22. web.setHtml(html)
    23. doc = QTextEdit()
    24. doc.setDocument(web)
    25. ly.addWidget(doc)
    26. dlg.setLayout(ly)
    27. dlg.show()
    28.  
    29. web = QWebView()
    30. web.setHtml(html)
    31. web.show()
    32.  
    33. sys.exit(app.exec_())
    To copy to clipboard, switch view to plain text mode 


    Update:
    It seems QTextDocument ignore CSS at all. HTML bellow has no impact (but works fine with QWebView).
    Qt Code:
    1. <table width=100% border=1>
    2. <tr><td width=33%>2</td><td width=34%>2</td><td width=33% ><div style="float:left;display:inline-block;width:50%;text-align:right;">3</div><div style="float:left;display:inline-block;width:50%;text-align: left;">.6</div></td></tr>
    3. </table>
    To copy to clipboard, switch view to plain text mode 
    The same with QTextDocument.setDefaultStyleSheet


    Added after 36 minutes:


    According documentation, QTextDocument supports only subset of CSS . Fixed with table-in-table (cellpadding=0 cellspacing=0)
    Last edited by miso; 17th June 2013 at 14:45.

Similar Threads

  1. Replies: 8
    Last Post: 3rd September 2013, 10:51
  2. QTextDocument::addResource in QWebView
    By NullPointer in forum Newbie
    Replies: 1
    Last Post: 27th July 2011, 03:04
  3. QTextDocument Html URL
    By bunjee in forum Qt Programming
    Replies: 2
    Last Post: 20th February 2008, 18:00
  4. QTextDocument and insertImage
    By bunjee in forum Qt Programming
    Replies: 13
    Last Post: 23rd January 2008, 22:03
  5. QTextDocument?
    By thomasjoy in forum Qt Programming
    Replies: 1
    Last Post: 15th August 2007, 23:42

Tags for this Thread

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.