当前位置: 首页>>代码示例>>Python>>正文


Python QTextDocument.setHtml方法代码示例

本文整理汇总了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())
开发者ID:Longhanks,项目名称:QHN,代码行数:9,代码来源:storywidget.py

示例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()
开发者ID:gis-support,项目名称:DIVI-QGIS-Plugin,代码行数:33,代码来源:ActivitiesModel.py

示例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()
开发者ID:duniter,项目名称:sakia,代码行数:27,代码来源:delegate.py

示例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()
开发者ID:phildavies10,项目名称:Pycharm_workspace,代码行数:29,代码来源:viewsUtils.py

示例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()
开发者ID:P4ncake,项目名称:weboob,代码行数:27,代码来源:qt.py

示例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
开发者ID:zisecheng,项目名称:retext,代码行数:10,代码来源:window.py

示例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()))
开发者ID:P4ncake,项目名称:weboob,代码行数:10,代码来源:qt.py

示例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
开发者ID:retext-project,项目名称:retext,代码行数:10,代码来源:window.py

示例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())
开发者ID:gis-support,项目名称:DIVI-QGIS-Plugin,代码行数:10,代码来源:ActivitiesModel.py

示例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
开发者ID:OpenNumismat,项目名称:open-numismat,代码行数:11,代码来源:Converters.py

示例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)
开发者ID:Longhanks,项目名称:QHN,代码行数:12,代码来源:storywidget.py

示例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())
开发者ID:duniter,项目名称:sakia,代码行数:12,代码来源:delegate.py

示例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)
开发者ID:hovo1990,项目名称:GROM,代码行数:13,代码来源:gro_model.py

示例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())
开发者ID:Aldenis2112,项目名称:qutepart,代码行数:14,代码来源:htmldelegate.py

示例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)
开发者ID:lidingke,项目名称:photodarkening,代码行数:15,代码来源:pdfcreater.py


注:本文中的PyQt5.QtGui.QTextDocument.setHtml方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。