本文整理汇总了Python中PyQt4.QtGui.QTextDocument.setHtml方法的典型用法代码示例。如果您正苦于以下问题:Python QTextDocument.setHtml方法的具体用法?Python QTextDocument.setHtml怎么用?Python QTextDocument.setHtml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QTextDocument
的用法示例。
在下文中一共展示了QTextDocument.setHtml方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sizeHint
# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import setHtml [as 别名]
def sizeHint(self, option, index):
text = index.model().data(index).toString()
document = QTextDocument()
document.setDefaultFont(option.font)
document.setHtml(text)
return QSize(document.idealWidth() + 5,
option.fontMetrics.height())
示例2: drawContents
# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import setHtml [as 别名]
def drawContents(self, painter):
"""
Reimplementation of drawContents to limit the drawing
inside `textRext`.
"""
painter.setPen(self.__color)
painter.setFont(self.font())
if self.__textRect:
rect = self.__textRect
else:
rect = self.rect().adjusted(5, 5, -5, -5)
if Qt.mightBeRichText(self.__message):
doc = QTextDocument()
doc.setHtml(self.__message)
doc.setTextWidth(rect.width())
cursor = QTextCursor(doc)
cursor.select(QTextCursor.Document)
fmt = QTextBlockFormat()
fmt.setAlignment(self.__alignment)
cursor.mergeBlockFormat(fmt)
painter.save()
painter.translate(rect.topLeft())
doc.drawContents(painter)
painter.restore()
else:
painter.drawText(rect, self.__alignment, self.__message)
示例3: FeatureShape
# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import setHtml [as 别名]
class FeatureShape(LabeledPolygonShape):
def draw(self, painter, xMap, yMap, canvasRect):
self._setup_painter(painter)
self._set_outer_pen_and_brush(painter, xMap, yMap)
rtmin = self.item.rtmin
rtmax = self.item.rtmax
mzmin = self.item.mzmin
mzmax = self.item.mzmax
self._draw_polygon(painter, xMap, yMap, (rtmin, rtmax, mzmin, mzmax))
self._set_inner_pen_and_brush(painter, xMap, yMap)
for mass_trace in self.item.mass_traces:
self._draw_polygon(painter, xMap, yMap, mass_trace)
if self.label is not None:
self._draw_label(painter, xMap, yMap)
def _draw_label(self, painter, xMap, yMap):
self.text = QTextDocument()
self.text.setDefaultStyleSheet("""div { color: rgb(%d, %d, %d); }""" % self.color)
self.text.setHtml("<div>%s</div>" % (self.label, ))
x0 = xMap.transform(self.item.rtmax)
# y0: height between m0 and m1 masstrace if m1 exists, else at height of m0
yi = sorted(m.mzmin for m in self.item.mass_traces)
if len(yi) >= 2:
y0 = yMap.transform(0.5 * yi[0] + 0.5 * yi[1])
else:
y0 = yMap.transform(yi[0])
h = self.text.size().height()
painter.translate(x0, y0 - 0.5 * h)
self.text.drawContents(painter)
示例4: __render_fullname
# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import setHtml [as 别名]
def __render_fullname(self, width, index):
fullname = index.data(self.FullnameRole).toPyObject()
doc = QTextDocument()
doc.setHtml("<b>%s</b>" % fullname)
doc.setDefaultFont(FULLNAME_FONT)
doc.setTextWidth(self.__calculate_text_width(width))
return doc
示例5: paint
# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import setHtml [as 别名]
def paint(self, painter, option, index):
optionV4 = QStyleOptionViewItemV4(option)
self.initStyleOption(optionV4, index)
style = optionV4.widget.style() if optionV4.widget else QApplication.style()
doc = QTextDocument()
doc.setHtml(optionV4.text)
# painting item without text
optionV4.text = QString()
style.drawControl(QStyle.CE_ItemViewItem, optionV4, painter)
ctx = QAbstractTextDocumentLayout.PaintContext()
# Hilight text if item is selected
if optionV4.state & QStyle.State_Selected:
ctx.palette.setColor(QPalette.Text, optionV4.palette.color(QPalette.Active, QPalette.HighlightedText))
textRect = style.subElementRect(QStyle.SE_ItemViewItemText, optionV4)
painter.save()
painter.translate(textRect.topLeft())
painter.setClipRect(textRect.translated(-textRect.topLeft()))
doc.documentLayout().draw(painter, ctx)
painter.restore()
示例6: paint
# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import setHtml [as 别名]
def paint(self, painter, option, index):
"""Render the delegate for the item."""
if index.column() != self._html_column:
return QStyledItemDelegate.paint(self, painter, option, index)
options = QStyleOptionViewItemV4(option)
self.initStyleOption(options, index)
if options.widget is None:
style = QApplication.style()
else:
style = options.widget.style()
doc = QTextDocument()
doc.setHtml(options.text)
options.text = ""
style.drawControl(QStyle.CE_ItemViewItem, options, painter)
ctx = QAbstractTextDocumentLayout.PaintContext()
textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
painter.save()
painter.translate(textRect.topLeft())
painter.setClipRect(textRect.translated(-textRect.topLeft()))
doc.documentLayout().draw(painter, ctx)
painter.restore()
示例7: paint
# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import setHtml [as 别名]
def paint(self, painter, option, index):
"""QStyledItemDelegate.paint implementation
"""
option.state &= ~QStyle.State_HasFocus # never draw focus rect
options = QStyleOptionViewItemV4(option)
self.initStyleOption(options, index)
style = QApplication.style() if options.widget is None else options.widget.style()
doc = QTextDocument()
doc.setDocumentMargin(1)
doc.setHtml(options.text)
# bad long (multiline) strings processing doc.setTextWidth(options.rect.width())
options.text = ""
style.drawControl(QStyle.CE_ItemViewItem, options, painter)
ctx = QAbstractTextDocumentLayout.PaintContext()
# Highlighting text if item is selected
if option.state & QStyle.State_Selected:
ctx.palette.setColor(QPalette.Text, option.palette.color(QPalette.Active, QPalette.HighlightedText))
textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
painter.save()
painter.translate(textRect.topLeft())
painter.setClipRect(textRect.translated(-textRect.topLeft()))
doc.documentLayout().draw(painter, ctx)
painter.restore()
示例8: _copy
# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import setHtml [as 别名]
def _copy(self, index):
doc = QTextDocument()
doc.setHtml(index.data(Qt.DisplayRole).toString())
clipboard = QApplication.clipboard()
richTextData = QMimeData()
richTextData.setHtml(index.data(Qt.DisplayRole).toString())
richTextData.setText(doc.toPlainText())
clipboard.setMimeData(richTextData)
示例9: sizeHint
# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import setHtml [as 别名]
def sizeHint(self, option, index):
options = QStyleOptionViewItemV4(option)
self.initStyleOption(options,index)
doc = QTextDocument()
doc.setHtml(options.text)
doc.setTextWidth(options.rect.width())
return QtCore.QSize(doc.idealWidth(), doc.size().height())
示例10: sizeHint
# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import setHtml [as 别名]
def sizeHint(self, option, index):
"""Calculate the needed size."""
options = QStyleOptionViewItemV4(option)
self.initStyleOption(options, index)
doc = QTextDocument()
doc.setHtml(options.text)
doc.setTextWidth(options.rect.width())
return QSize(doc.idealWidth(), doc.size().height())
示例11: sizeHint
# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import setHtml [as 别名]
def sizeHint(self, option, index):
optionV4 = QStyleOptionViewItemV4(option)
self.initStyleOption(optionV4, index)
doc = QTextDocument()
doc.setHtml(optionV4.text)
doc.setTextWidth(optionV4.rect.width())
return QSize(doc.idealWidth(), max(doc.size().height(), optionV4.decorationSize.height()))
示例12: sizeHint
# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import setHtml [as 别名]
def sizeHint(self, option, index):
fm = option.fontMetrics
if index.column() in (SRC_ADDR, DST_ADDR):
text = index.model().data(index).toString()
document = QTextDocument()
document.setDefaultFont(option.font)
document.setHtml(text)
#document.setPageSize(option.rect.size())
return QSize(document.idealWidth() + 5, 1.3 * fm.height())
return QItemDelegate.sizeHint(self, option, index)
示例13: writePdf
# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import setHtml [as 别名]
def writePdf(dir_):
newbody = originHTML.format(**htmlpara)
printer = QPrinter()
printer.setOutputFormat(QPrinter.PdfFormat)
printer.setOutputFileName(dir_+'.pdf')
printer.setPageSize(QPrinter.A4)
text = QTextDocument()
text.setHtml(newbody.decode('utf-8'))
text.print_(printer)
示例14: __render_username
# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import setHtml [as 别名]
def __render_username(self, width, index):
username_string = index.data(self.UsernameRole).toPyObject()
username = QTextDocument()
if username_string != '':
username.setHtml("<span style='color: #666;'>@%s</span>" % username_string)
else:
username.setHtml("<span style='color: #666;'></span>" % username_string)
username.setDefaultFont(USERNAME_FONT)
username.setTextWidth(self.__calculate_text_width(width))
return username
示例15: __render_status_message
# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import setHtml [as 别名]
def __render_status_message(self, width, index):
message = unicode(index.data(self.MessageRole).toPyObject())
urls = index.data(self.URLsEntitiesRole).toPyObject()
for url in urls:
pretty_url = "<a href='%s'>%s</a>" % (url.url, url.display_text)
message = message.replace(url.search_for, pretty_url)
doc = QTextDocument()
doc.setHtml(message)
doc.setTextWidth(self.__calculate_text_width(width))
return doc