本文整理汇总了Python中PyQt5.QtGui.QTextDocument.setHtml方法的典型用法代码示例。如果您正苦于以下问题:Python QTextDocument.setHtml方法的具体用法?Python QTextDocument.setHtml怎么用?Python QTextDocument.setHtml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtGui.QTextDocument
的用法示例。
在下文中一共展示了QTextDocument.setHtml方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sizeHint
# 需要导入模块: from PyQt5.QtGui import QTextDocument [as 别名]
# 或者: from PyQt5.QtGui.QTextDocument import setHtml [as 别名]
def sizeHint(self, option, index):
text = index.model().data(index)
doc = QTextDocument()
doc.setHtml(text)
width = index.model().data(index, Qt.UserRole + 1337)
doc.setTextWidth(width)
return QSize(doc.idealWidth(), doc.size().height())
示例2: paint
# 需要导入模块: from PyQt5.QtGui import QTextDocument [as 别名]
# 或者: from PyQt5.QtGui.QTextDocument import setHtml [as 别名]
def paint(self, painter, option, index):
options = QStyleOptionViewItem(option)
item = index.data(Qt.UserRole)
if isinstance(item, (CommentItem, ChangeItem)):
options.decorationAlignment = Qt.AlignHCenter
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()
# Highlighting 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, options)
painter.save()
painter.translate(textRect.topLeft())
painter.setClipRect(textRect.translated(-textRect.topLeft()))
doc.documentLayout().draw(painter, ctx)
painter.restore()
示例3: paint
# 需要导入模块: from PyQt5.QtGui import QTextDocument [as 别名]
# 或者: from PyQt5.QtGui.QTextDocument import setHtml [as 别名]
def paint(self, painter, option, index):
self.initStyleOption(option, index)
style = QApplication.style()
doc = QTextDocument()
if index.column() in (NetworkTableModel.columns_types.index('address'),
NetworkTableModel.columns_types.index('port'),
NetworkTableModel.columns_types.index('api')):
doc.setHtml(option.text)
else:
doc.setPlainText(option.text)
option.text = ""
style.drawControl(QStyle.CE_ItemViewItem, option, painter)
ctx = QAbstractTextDocumentLayout.PaintContext()
text_rect = style.subElementRect(QStyle.SE_ItemViewItemText, option)
painter.save()
painter.translate(text_rect.topLeft())
painter.setClipRect(text_rect.translated(-text_rect.topLeft()))
doc.documentLayout().draw(painter, ctx)
painter.restore()
示例4: paint
# 需要导入模块: from PyQt5.QtGui import QTextDocument [as 别名]
# 或者: from PyQt5.QtGui.QTextDocument import setHtml [as 别名]
def paint(self, painter, option, index):
text = index.model().data(index, Qt.DisplayRole)
document = QTextDocument()
# metrics = QFontMetrics(document.defaultFont())
metrics = painter.fontMetrics()
# font = QFont()
# font.setPointSize(12)
document.setDefaultFont(G.entriesFont)
if index.column() == 0:
document.setTextWidth(69)
elif index.column() == 1:
document.setTextWidth(514)
if option.state & QStyle.State_Selected:
document.setHtml("<b bgcolor=#E6E600> <font size={} font color={}>{}"
"</font></b>".format("2", G.selectionColor, text))
else:
w = metrics.boundingRect('W').width()
# print(w)
txt = text[0:(514*4)//w]
document.setHtml("<p align (center) bgcolor=white> <font size={} "
"font color={}>{}"
"</font></p>".format("2", "black", txt))
painter.save()
painter.translate(option.rect.x(), option.rect.y())
document.drawContents(painter)
painter.restore()
示例5: paint
# 需要导入模块: from PyQt5.QtGui import QTextDocument [as 别名]
# 或者: from PyQt5.QtGui.QTextDocument import setHtml [as 别名]
def paint(self, painter, option, index):
option = QStyleOptionViewItem(option) # copy option
self.initStyleOption(option, index)
style = option.widget.style() if option.widget else QApplication.style()
doc = QTextDocument()
doc.setHtml(option.text)
# painting item without text
option.text = ""
style.drawControl(QStyle.CE_ItemViewItem, option, painter)
ctx = QAbstractTextDocumentLayout.PaintContext()
# Hilight 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, option)
painter.save()
painter.translate(textRect.topLeft())
painter.setClipRect(textRect.translated(-textRect.topLeft()))
doc.documentLayout().draw(painter, ctx)
painter.restore()
示例6: textDocument
# 需要导入模块: from PyQt5.QtGui import QTextDocument [as 别名]
# 或者: from PyQt5.QtGui.QTextDocument import setHtml [as 别名]
def textDocument(self):
td = QTextDocument()
td.setMetaInformation(QTextDocument.DocumentTitle, self.getDocumentTitle())
if self.ss:
td.setDefaultStyleSheet(self.ss)
td.setHtml(self.getHtml())
td.setDefaultFont(globalSettings.font)
return td
示例7: sizeHint
# 需要导入模块: from PyQt5.QtGui import QTextDocument [as 别名]
# 或者: from PyQt5.QtGui.QTextDocument import setHtml [as 别名]
def sizeHint(self, option, index):
self.initStyleOption(option, index)
doc = QTextDocument()
doc.setHtml(option.text)
doc.setTextWidth(option.rect.width())
return QSize(doc.idealWidth(), max(doc.size().height(), option.decorationSize.height()))
示例8: textDocument
# 需要导入模块: from PyQt5.QtGui import QTextDocument [as 别名]
# 或者: from PyQt5.QtGui.QTextDocument import setHtml [as 别名]
def textDocument(self, title, htmltext):
td = QTextDocument()
td.setMetaInformation(QTextDocument.DocumentTitle, title)
if self.ss:
td.setDefaultStyleSheet(self.ss)
td.setHtml(htmltext)
td.setDefaultFont(globalSettings.font)
return td
示例9: sizeHint
# 需要导入模块: from PyQt5.QtGui import QTextDocument [as 别名]
# 或者: from PyQt5.QtGui.QTextDocument import setHtml [as 别名]
def sizeHint(self, option, index):
options = QStyleOptionViewItem(option)
self.initStyleOption(options,index)
doc = QTextDocument()
doc.setHtml(options.text)
doc.setTextWidth(options.rect.width())
return QSize(doc.idealWidth(), doc.size().height())
示例10: htmlToPlainText
# 需要导入模块: from PyQt5.QtGui import QTextDocument [as 别名]
# 或者: from PyQt5.QtGui.QTextDocument import setHtml [as 别名]
def htmlToPlainText(text):
RICH_PREFIX = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" '\
'"http://www.w3.org/TR/REC-html40/strict.dtd">'
if text.startswith(RICH_PREFIX):
document = QTextDocument()
document.setHtml(text)
text = document.toPlainText()
return text
示例11: paint
# 需要导入模块: from PyQt5.QtGui import QTextDocument [as 别名]
# 或者: from PyQt5.QtGui.QTextDocument import setHtml [as 别名]
def paint(self, painter, option, index):
text = index.data()
doc = QTextDocument()
doc.setHtml(text)
doc.setTextWidth(option.rect.width())
painter.save()
painter.translate(option.rect.x(), option.rect.y())
doc.drawContents(painter)
painter.restore()
index.model().setData(index, option.rect.width(), Qt.UserRole + 1337)
示例12: sizeHint
# 需要导入模块: from PyQt5.QtGui import QTextDocument [as 别名]
# 或者: from PyQt5.QtGui.QTextDocument import setHtml [as 别名]
def sizeHint(self, option, index):
self.initStyleOption(option, index)
doc = QTextDocument()
if index.column() == HistoryTableModel.columns_types.index('pubkey'):
doc.setHtml(option.text)
else:
doc.setPlainText("")
doc.setTextWidth(-1)
return QSize(doc.idealWidth(), doc.size().height())
示例13: sizeHint
# 需要导入模块: from PyQt5.QtGui import QTextDocument [as 别名]
# 或者: from PyQt5.QtGui.QTextDocument import setHtml [as 别名]
def sizeHint(self, option, index):
fm = option.fontMetrics
if index.column() == residNum:
return QSize(fm.width("9,999,999"), fm.height())
if index.column() == residName:
text = index.model().data(index)
document = QTextDocument()
document.setDefaultFont(option.font)
document.setHtml(text)
return QSize(document.idealWidth() + 5, fm.height())
return QStyledItemDelegate.sizeHint(self, option, index)
示例14: sizeHint
# 需要导入模块: from PyQt5.QtGui import QTextDocument [as 别名]
# 或者: from PyQt5.QtGui.QTextDocument import setHtml [as 别名]
def sizeHint(self, option, index):
"""QStyledItemDelegate.sizeHint implementation
"""
options = QStyleOptionViewItem(option)
self.initStyleOption(options,index)
doc = QTextDocument()
doc.setDocumentMargin(1)
# bad long (multiline) strings processing doc.setTextWidth(options.rect.width())
doc.setHtml(options.text)
return QSize(doc.idealWidth(),
QStyledItemDelegate.sizeHint(self, option, index).height())
示例15: savePdf
# 需要导入模块: from PyQt5.QtGui import QTextDocument [as 别名]
# 或者: from PyQt5.QtGui.QTextDocument import setHtml [as 别名]
def savePdf(self,fileName):
pt = QPdfWriter(fileName)
# pt.logicalDpiX
pt.setPageSize(QPagedPaintDevice.A4)
# print('resolution',pt.resolution())
pt.setResolution(10000)
# print('resolution',pt.resolution())
textDocument = QTextDocument()
textDocument.setHtml(self.pcontext.thtmlGet())
textDocument.print_(pt)
textDocument.end()
print('pdf creat = ',fileName)