Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PyQt4.QtGui import *
- from PyQt4.QtCore import *
- from PyQt4.Qt import Qt
- from PyQt4.QtWebKit import QWebView, QWebSettings
- [......]
- def addHtmlItem(self, html, data):
- '''Adds a new QTextEdit widget containing the given HTMl as an item in the list.
- '''
- item = QListWidgetItem()
- item.setData(Qt.UserRole, data)
- self.addItem(item)
- item.setSizeHint(self._htmlItemWidget.frameSize())
- label = QLabel()
- label.setTextInteractionFlags(Qt.NoTextInteraction)
- html = u'<html><body style="margin:0px 0px 0px 4px">{0}</body></html>'.format(html)
- if '<img' in html:
- self._htmlItemWidgetFinishedLoading = False
- self._htmlItemWidget.setHtml(html)
- pm = QImage(self._htmlItemWidget.size(), QImage.Format_ARGB32)
- pm.fill(Qt.transparent)
- # wait for it to finish loading, then render
- q_app = QApplication.instance()
- while not self._htmlItemWidgetFinishedLoading:
- q_app.processEvents(QEventLoop.WaitForMoreEvents | QEventLoop.ExcludeUserInputEvents)
- self._htmlItemWidget.render(pm, flags=QWidget.DrawChildren)
- label.setPixmap(QPixmap.fromImage(pm))
- else:
- label.setText(html)
- self.setItemWidget(item, label)
Add Comment
Please, Sign In to add comment