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


Python QTextDocument.setHtml方法代码示例

本文整理汇总了Python中PyQt5.Qt.QTextDocument.setHtml方法的典型用法代码示例。如果您正苦于以下问题:Python QTextDocument.setHtml方法的具体用法?Python QTextDocument.setHtml怎么用?Python QTextDocument.setHtml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt5.Qt.QTextDocument的用法示例。


在下文中一共展示了QTextDocument.setHtml方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: paint

# 需要导入模块: from PyQt5.Qt import QTextDocument [as 别名]
# 或者: from PyQt5.Qt.QTextDocument import setHtml [as 别名]
 def paint(self, painter, option, index):
     QStyledItemDelegate.paint(self, painter, option, index)
     text, positions = index.data(Qt.UserRole)
     self.initStyleOption(option, index)
     painter.save()
     painter.setFont(option.font)
     p = option.palette
     c = p.HighlightedText if option.state & QStyle.State_Selected else p.Text
     group = (p.Active if option.state & QStyle.State_Active else p.Inactive)
     c = p.color(group, c)
     painter.setClipRect(option.rect)
     if positions is None or -1 in positions:
         painter.setPen(c)
         painter.drawText(option.rect, Qt.AlignLeft | Qt.AlignVCenter | Qt.TextSingleLine, text)
     else:
         to = QTextOption()
         to.setWrapMode(to.NoWrap)
         to.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
         positions = sorted(set(positions) - {-1}, reverse=True)
         text = '<body>%s</body>' % make_highlighted_text(Results.EMPH, text, positions)
         doc = QTextDocument()
         c = 'rgb(%d, %d, %d)'%c.getRgb()[:3]
         doc.setDefaultStyleSheet(' body { color: %s }'%c)
         doc.setHtml(text)
         doc.setDefaultFont(option.font)
         doc.setDocumentMargin(0.0)
         doc.setDefaultTextOption(to)
         height = doc.size().height()
         painter.translate(option.rect.left(), option.rect.top() + (max(0, option.rect.height() - height) // 2))
         doc.drawContents(painter)
     painter.restore()
开发者ID:,项目名称:,代码行数:33,代码来源:

示例2: to_doc

# 需要导入模块: from PyQt5.Qt import QTextDocument [as 别名]
# 或者: from PyQt5.Qt.QTextDocument import setHtml [as 别名]
 def to_doc(self, index, option=None):
     doc = QTextDocument()
     if option is not None and option.state & QStyle.State_Selected:
         p = option.palette
         group = p.Active if option.state & QStyle.State_Active else p.Inactive
         c = p.color(group, p.HighlightedText)
         c = "rgb(%d, %d, %d)" % c.getRgb()[:3]
         doc.setDefaultStyleSheet(" * { color: %s }" % c)
     doc.setHtml(index.data() or "")
     return doc
开发者ID:j-howell,项目名称:calibre,代码行数:12,代码来源:single_download.py

示例3: copy_to_clipboard

# 需要导入模块: from PyQt5.Qt import QTextDocument [as 别名]
# 或者: from PyQt5.Qt.QTextDocument import setHtml [as 别名]
 def copy_to_clipboard(self, *args):
     d = QTextDocument()
     d.setHtml(self.msg_label.text())
     QApplication.clipboard().setText(
             u'calibre, version %s (%s, embedded-python: %s)\n%s: %s\n\n%s' %
             (__version__, sys.platform, isfrozen,
                 unicode(self.windowTitle()), unicode(d.toPlainText()),
                 unicode(self.det_msg.toPlainText())))
     if hasattr(self, 'ctc_button'):
         self.ctc_button.setText(_('Copied'))
开发者ID:AEliu,项目名称:calibre,代码行数:12,代码来源:message_box.py

示例4: render_and_save

# 需要导入模块: from PyQt5.Qt import QTextDocument [as 别名]
# 或者: from PyQt5.Qt.QTextDocument import setHtml [as 别名]
    def render_and_save(self):
        path = os.path.join(options.REPORTS_DIR, *(datetime.date.today().isoformat().split('-')))
        if not os.path.exists(path):
            os.makedirs(path)

        path = os.path.join(path, '{}.odt'.format(self.user))
        document = QTextDocument()
        document.setHtml(self.render())
        QTextDocumentWriter(path).write(document)

        self.client.save()
        report = db.Report(path=path, client_id=self.client.id)
        report.save()
        return report
开发者ID:aq1,项目名称:Hospital-Helper-2,代码行数:16,代码来源:report.py

示例5: CcCommentsDelegate

# 需要导入模块: from PyQt5.Qt import QTextDocument [as 别名]
# 或者: from PyQt5.Qt.QTextDocument import setHtml [as 别名]
class CcCommentsDelegate(QStyledItemDelegate):  # {{{

    '''
    Delegate for comments data.
    '''

    def __init__(self, parent):
        QStyledItemDelegate.__init__(self, parent)
        self.document = QTextDocument()

    def paint(self, painter, option, index):
        self.initStyleOption(option, index)
        style = QApplication.style() if option.widget is None \
                                                else option.widget.style()
        self.document.setHtml(option.text)
        style.drawPrimitive(QStyle.PE_PanelItemViewItem, option, painter, widget=option.widget)
        rect = style.subElementRect(QStyle.SE_ItemViewItemDecoration, option, self.parent())
        ic = option.icon
        if rect.isValid() and not ic.isNull():
            sz = ic.actualSize(option.decorationSize)
            painter.drawPixmap(rect.topLeft(), ic.pixmap(sz))
        ctx = QAbstractTextDocumentLayout.PaintContext()
        ctx.palette = option.palette
        if option.state & QStyle.State_Selected:
            ctx.palette.setColor(ctx.palette.Text, ctx.palette.color(ctx.palette.HighlightedText))
        textRect = style.subElementRect(QStyle.SE_ItemViewItemText, option, self.parent())
        painter.save()
        painter.translate(textRect.topLeft())
        painter.setClipRect(textRect.translated(-textRect.topLeft()))
        self.document.documentLayout().draw(painter, ctx)
        painter.restore()

    def createEditor(self, parent, option, index):
        m = index.model()
        col = m.column_map[index.column()]
        if check_key_modifier(Qt.ControlModifier):
            text = ''
        else:
            text = m.db.data[index.row()][m.custom_columns[col]['rec_index']]
        editor = CommentsDialog(parent, text, column_name=m.custom_columns[col]['name'])
        d = editor.exec_()
        if d:
            m.setData(index, (editor.textbox.html), Qt.EditRole)
        return None

    def setModelData(self, editor, model, index):
        model.setData(index, (editor.textbox.html), Qt.EditRole)
开发者ID:AEliu,项目名称:calibre,代码行数:49,代码来源:delegates.py

示例6: to_doc

# 需要导入模块: from PyQt5.Qt import QTextDocument [as 别名]
# 或者: from PyQt5.Qt.QTextDocument import setHtml [as 别名]
 def to_doc(self, index):
     data = index.data(Qt.UserRole)
     if data is None:
         html = _('<b>This shortcut no longer exists</b>')
     elif data.is_shortcut:
         shortcut = data.data
         # Shortcut
         keys = [unicode(k.toString(k.NativeText)) for k in shortcut['keys']]
         if not keys:
             keys = _('None')
         else:
             keys = ', '.join(keys)
         html = '<b>%s</b><br>%s: %s'%(shortcut['name'], _('Shortcuts'), keys)
     else:
         # Group
         html = '<h3>%s</h3>'%data.data
     doc =  QTextDocument()
     doc.setHtml(html)
     return doc
开发者ID:AtulKumar2,项目名称:calibre,代码行数:21,代码来源:keyboard.py

示例7: generatePDF

# 需要导入模块: from PyQt5.Qt import QTextDocument [as 别名]
# 或者: from PyQt5.Qt.QTextDocument import setHtml [as 别名]
    def generatePDF(self, contenido):
        hoy = str(datetime.datetime.now().year) + str(datetime.datetime.now().month) + str(datetime.datetime.now().day) + str(datetime.datetime.now().hour) + str(datetime.datetime.now().minute) + str(datetime.datetime.now().second)

        nombrePdf = '../archivos/' + str(hoy + 'LIST') + '.pdf'

        fecha = str(datetime.datetime.now())

        html =  """
                     <table width="600">
                        <tr width="600" color="#000000">
                            <td width="80%">

                            </td>
                            <td width="20%" align="right">
                                <IMG SRC="kde1.png">
                            </td>
                        </tr>

                    </table>

                   <hr>
                    <br>
                    <p>
                        SALDOS
                    </p>
                    <br>

                  """+ contenido

        doc = QTextDocument()
        doc.setHtml(html)

        printer = QPrinter()
        printer.setOutputFileName(nombrePdf)

        printer.setOutputFormat(QPrinter.PdfFormat)
        doc.print(printer)
        printer.newPage()
        url = QUrl
        url = QUrl(nombrePdf)
        QDesktopServices.openUrl(url)
开发者ID:Zeldex,项目名称:PQt5-Stock-Venta-CuentaCorriente,代码行数:43,代码来源:pEstadisticas.py

示例8: CcCommentsDelegate

# 需要导入模块: from PyQt5.Qt import QTextDocument [as 别名]
# 或者: from PyQt5.Qt.QTextDocument import setHtml [as 别名]
class CcCommentsDelegate(QStyledItemDelegate):  # {{{

    '''
    Delegate for comments data.
    '''

    def __init__(self, parent):
        QStyledItemDelegate.__init__(self, parent)
        self.document = QTextDocument()

    def paint(self, painter, option, index):
        self.initStyleOption(option, index)
        style = QApplication.style() if option.widget is None \
                                                else option.widget.style()
        self.document.setHtml(option.text)
        option.text = u''
        if hasattr(QStyle, 'CE_ItemViewItem'):
            style.drawControl(QStyle.CE_ItemViewItem, option, painter)
        ctx = QAbstractTextDocumentLayout.PaintContext()
        ctx.palette = option.palette  # .setColor(QPalette.Text, QColor("red"));
        if hasattr(QStyle, 'SE_ItemViewItemText'):
            textRect = style.subElementRect(QStyle.SE_ItemViewItemText, option)
            painter.save()
            painter.translate(textRect.topLeft())
            painter.setClipRect(textRect.translated(-textRect.topLeft()))
            self.document.documentLayout().draw(painter, ctx)
            painter.restore()

    def createEditor(self, parent, option, index):
        m = index.model()
        col = m.column_map[index.column()]
        text = m.db.data[index.row()][m.custom_columns[col]['rec_index']]
        editor = CommentsDialog(parent, text, column_name=m.custom_columns[col]['name'])
        d = editor.exec_()
        if d:
            m.setData(index, (editor.textbox.html), Qt.EditRole)
        return None

    def setModelData(self, editor, model, index):
        model.setData(index, (editor.textbox.html), Qt.EditRole)
开发者ID:AtulKumar2,项目名称:calibre,代码行数:42,代码来源:delegates.py

示例9: createFactura

# 需要导入模块: from PyQt5.Qt import QTextDocument [as 别名]
# 或者: from PyQt5.Qt.QTextDocument import setHtml [as 别名]

#.........这里部分代码省略.........
                    _______________________________________________________________________________________________________
                    <br>
                    <p>
                        DETALLES DE LA COMPRA:
                    </p>
                    <br>
                    <table width="600" height="0" style="border-color: black; border-width: 0.5px; border-spacing: 0;">
                      <tr  style=" background-color: gray; border-style: inset;">
                        <td width="10%"  align="center" valign="middle">
                            <b>
                            CANT
                            </b>
                        </td>
                        <td width="20%"  align="center" valign="middle">
                            <b>
                                PRODUCTO
                            </b>
                        </td>
                        <td width="50%"  align="center" valign="middle">
                            <b>
                            DESCRIPCION
                            </b>
                        </td>
                        <td width="10%"  align="center" valign="middle">
                            <b>
                            PREC <br>UNIT
                            </b>
                        </td>
                        <td width="10%"  align="center" valign="middle">
                            <b>
                            PREC <br>TOT
                            </b>
                        </td>
                      </tr>
                  </table>

                  <br>
                  <br>
                  <br>
                  <br>

                  <table  height="350" width="600" style="border-color: gray; border-width: .4px; border-collapse: collapse;">
                      """ + listTransaccionTable + """
                  </table>
                    <br>
                    <br>
                    <table width="600" border="0.5" height="0" style="border-color: black; border-width: 0.5px; border-spacing: 0;">
                        <tr >
                            <td width="90%" align="right">
                                <br>
                                TOTAL..................................................................................................................
                                <br>
                            </td>
                            <td width="10%" align="center">
                              <br> $ """ + total + """<br>
                            </td>
                        </tr>
                    </table>

                    <br>
                    <br>
                    <br>
                    <p width="600" align="center" style=" font-size: 10; " >
                    Por cualquier consulta, sobre este recibo, dirigirse al local que se encuentra ubicado en la calle
                    independencia 450. <br> O Comunicarse a los telefonos 03382-123123123 / 4231231
                    </p>
                    <br>
                    <br>
                    <br>
                    <br>
                    <br>
                    _______________________________________________________________________________________________________
                    <br>
                    <table width="600">
                        <tr>
                            <td align="right" width="80%">
                            FECHA/HORA : """+ fecha + """
                            </td>
                            <td align="right">
                            N° : """+ str(idRecibo) +"""
                            </td>
                        </tr>
                    </table>
                    _______________________________________________________________________________________________________
                """

        doc = QTextDocument()
        doc.setHtml(html)
        #doc.setDefaultStyleSheet(style)
        printer = QPrinter()
        printer.setOutputFileName(nombrePdf)

        printer.setOutputFormat(QPrinter.PdfFormat)
        doc.print(printer)
        printer.newPage()
        url = QUrl
        url = QUrl(nombrePdf)
        QDesktopServices.openUrl(url)

        """
开发者ID:Wilo,项目名称:Sistema-de-gestion-con-PyQt5,代码行数:104,代码来源:pTransacciones.py

示例10: createList

# 需要导入模块: from PyQt5.Qt import QTextDocument [as 别名]
# 或者: from PyQt5.Qt.QTextDocument import setHtml [as 别名]
    def createList(self):
        hoy = str(datetime.datetime.now().year) + str(datetime.datetime.now().month) + str(datetime.datetime.now().day) + str(datetime.datetime.now().hour) + str(datetime.datetime.now().minute) + str(datetime.datetime.now().second)

        nombrePdf = '../archivos/' + str(hoy + 'LIST') + '.pdf'
        listTable = ""
        for lista in self.listFinal:
            listTable += """
                                        <tr height="80">
                                            <td width="40%" align="center" >
                                            <br>""" + str(lista[0])  + """<br>
                                            </td>
                                            <td width="40%" >
                                                <br> &nbsp;&nbsp;""" + str(lista[1])  + """<br>
                                            </td>
                                            <td width="20%" >
                                               <br>&nbsp;&nbsp; """ + str(lista[2])  + """<br>
                                            </td>
                                        </tr>
                                   """


        subtitle = "Listado de clientes con deudas : "
        if self.type == 'PROV':
            subtitle = "Listado de deudas a proveedores : "


        fecha = str(datetime.datetime.now())
        html =  """
                     <table width="600">
                        <tr width="600" color="#000000">
                            <td width="80%">

                            </td>
                            <td width="20%" align="right">
                                <IMG SRC="kde1.png">
                            </td>
                        </tr>

                    </table>

                   <hr>
                    <br>
                    <p>
                        """+ subtitle + """
                    </p>
                    <br>
                    <table width="600" height="0" style="border-color: black; border-width: 0.5px; border-spacing: 0;">
                      <tr  style=" background-color: gray; border-style: inset;">
                        <td width="40%"  align="center" valign="middle">
                            <b>
                            APELLIDO
                            </b>
                        </td>
                        <td width="40%"  align="center" valign="middle">
                            <b>
                                NOMBRE
                            </b>
                        </td>
                        <td width="20%"  align="center" valign="middle">
                            <b>
                            DEUDA
                            </b>
                        </td>
                      </tr>
                  </table>

                  <br>
                  <br>

                  <table width="600" height="0" style="border-color: black; border-width: 0.5px; border-spacing: 0;">
                      """ + listTable + """
                  </table>
                    <br>
                    <br>

                    <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
                    <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
                    <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
                    <br>

                    <hr>
                    <br>
                    <table width="600">
                        <tr>
                            <td align="right" width="100%">
                            FECHA/HORA : """+ fecha + """
                            </td>
                        </tr>
                    </table>
                   <hr>
                """

        doc = QTextDocument()
        doc.setHtml(html)

        printer = QPrinter()
        printer.setOutputFileName(nombrePdf)

        printer.setOutputFormat(QPrinter.PdfFormat)
        doc.print(printer)
#.........这里部分代码省略.........
开发者ID:Zeldex,项目名称:PQt5-Stock-Venta-CuentaCorriente,代码行数:103,代码来源:windowList.py

示例11: to_doc

# 需要导入模块: from PyQt5.Qt import QTextDocument [as 别名]
# 或者: from PyQt5.Qt.QTextDocument import setHtml [as 别名]
 def to_doc(self, index):
     doc = QTextDocument()
     doc.setHtml(index.data())
     return doc
开发者ID:GaryMMugford,项目名称:calibre,代码行数:6,代码来源:shortcuts.py

示例12: generateList

# 需要导入模块: from PyQt5.Qt import QTextDocument [as 别名]
# 或者: from PyQt5.Qt.QTextDocument import setHtml [as 别名]
    def generateList(self):
        hoy = str(datetime.datetime.now().year) + str(datetime.datetime.now().month) + str(datetime.datetime.now().day) + str(datetime.datetime.now().hour) + str(datetime.datetime.now().minute) + str(datetime.datetime.now().second)

        nombrePdf = '../archivos/' + str(hoy + 'LIST') + '.pdf'
        listTable = ""
        for lista in self.listProducto:
            listTable += """
                                        <tr height="80">
                                            <td width="60%" align="left" >
                                            <br>""" + str(lista[1])  + """<br>
                                            </td>
                                            <td width="20%" align="center">
                                                <br> &nbsp;&nbsp;""" + str(lista[3])  + """<br>
                                            </td>
                                            <td width="20%" align="center">
                                               <br>&nbsp;&nbsp; """ + str(lista[2])  + """<br>
                                            </td>
                                        </tr>
                                   """


        fecha = str(datetime.datetime.now())
        html =  """
                     <table width="600">
                        <tr width="600" color="#000000">
                            <td width="80%">

                            </td>
                            <td width="20%" align="right">
                                <IMG SRC="kde1.png">
                            </td>
                        </tr>

                    </table>

                   <hr>
                    <br>
                    <p>
                        LISTADO DE PRODUCTOS SIN STOCK :
                    </p>
                    <br>
                    <table width="600" height="0" style="border-color: black; border-width: 0.5px; border-spacing: 0;">
                      <tr  style=" background-color: gray; border-style: inset;">
                        <td width="60%"  align="center" valign="middle">
                            <b>
                            PRODUCTOS
                            </b>
                        </td>
                        <td width="20%"  align="center" valign="middle">
                            <b>
                                CANTIDAD MINIMA
                            </b>
                        </td>
                        <td width="20%"  align="center" valign="middle">
                            <b>
                            CANTIDAD
                            </b>
                        </td>
                      </tr>
                  </table>

                  <br>
                  <br>

                  <table width="600" height="0" style="border-color: black; border-width: 0.5px; border-spacing: 0;">
                      """ + listTable + """
                  </table>
                    <br>
                    <br>

                    <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
                    <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
                    <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
                    <br>

                    <hr>
                    <br>
                    <table width="600">
                        <tr>
                            <td align="right" width="100%">
                            FECHA/HORA : """+ fecha + """
                            </td>
                        </tr>
                    </table>
                   <hr>
                """

        doc = QTextDocument()
        doc.setHtml(html)

        printer = QPrinter()
        printer.setOutputFileName(nombrePdf)

        printer.setOutputFormat(QPrinter.PdfFormat)
        doc.print(printer)
        printer.newPage()
        url = QUrl
        url = QUrl(nombrePdf)
        QDesktopServices.openUrl(url)
开发者ID:Zeldex,项目名称:PQt5-Stock-Venta-CuentaCorriente,代码行数:101,代码来源:windowNotification.py


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