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


Python QtGui.QTextDocument类代码示例

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


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

示例1: paint

    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,代码行数:25,代码来源:qt.py

示例2: paint

    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,代码行数:31,代码来源:ActivitiesModel.py

示例3: htmlToPlainText

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,代码行数:9,代码来源:Converters.py

示例4: paint

    def paint(self, painter, option, index):
        self.initStyleOption(option, index)

        foreground = index.data(Qt.ForegroundRole)
        font = index.data(Qt.FontRole)
        style = QApplication.style()

        doc = QTextDocument()
        if index.column() == HistoryTableModel.columns_types.index('pubkey'):
            doc.setHtml(option.text)
        else:
            doc.setPlainText(option.text)

        option.text = ""
        style.drawControl(QStyle.CE_ItemViewItem, option, painter)

        ctx = QAbstractTextDocumentLayout.PaintContext()
        if foreground:
            if foreground.isValid():
                ctx.palette.setColor(QPalette.Text, foreground)
        if font:
            doc.setDefaultFont(font)
        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,代码行数:29,代码来源:delegate.py

示例5: textDocument

	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,代码行数:8,代码来源:window.py

示例6: textDocument

	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,代码行数:8,代码来源:window.py

示例7: sizeHint

    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,代码行数:10,代码来源:delegate.py

示例8: pixmap

def pixmap(cursor, num_lines=6, scale=0.8):
    """Return a QPixmap displaying the selected lines of the document.

    If the cursor has no selection, num_lines are drawn.

    By default the text is drawn 0.8 * the normal font size. You can change
    that by supplying the scale parameter.

    """
    block = cursor.document().findBlock(cursor.selectionStart())
    c2 = QTextCursor(block)
    if cursor.hasSelection():
        c2.setPosition(cursor.selectionEnd(), QTextCursor.KeepAnchor)
        c2.movePosition(QTextCursor.EndOfBlock, QTextCursor.KeepAnchor)
    else:
        c2.movePosition(QTextCursor.NextBlock, QTextCursor.KeepAnchor, num_lines)

    data = textformats.formatData('editor')
    doc = QTextDocument()
    font = QFont(data.font)
    font.setPointSizeF(font.pointSizeF() * scale)
    doc.setDefaultFont(font)
    doc.setPlainText(c2.selection().toPlainText())
    if metainfo.info(cursor.document()).highlighting:
        highlighter.highlight(doc, state=tokeniter.state(block))
    size = doc.size().toSize() + QSize(8, -4)
    pix = QPixmap(size)
    pix.fill(data.baseColors['background'])
    doc.drawContents(QPainter(pix))
    return pix
开发者ID:19joho66,项目名称:frescobaldi,代码行数:30,代码来源:documenttooltip.py

示例9: __init__

 def __init__(self, my_book, parent=None):
     super().__init__(parent)
     self.book = my_book
     # Where we store the last-sought-for find string
     self.find_text = None
     # Register to read and write metadata
     my_book.get_meta_manager().register( C.MD_NO, self.read_meta, self.save_meta )
     # Set our only font (we don't care about the general font, only mono)
     # n.b. this gets the Book's default size as it hasn't loaded a document
     # yet.
     self.setFont(fonts.get_fixed(my_book.get_font_size()))
     # hook up to be notified of a change in font choice
     fonts.notify_me(self.font_change)
     # Set up our document not using the default one
     a_document = QTextDocument()
     a_document.setDocumentLayout(QPlainTextDocumentLayout(a_document))
     self.setDocument(a_document)
     # Turn off linewrap mode
     self.setLineWrapMode(QPlainTextEdit.NoWrap)
     # The following kludge allows us to get the correct highlight
     # color on focus-in. For unknown reasons Qt makes us use the
     # "Inactive" color group even after focus-in. See focusInEvent()
     # and focusOutEvent() below.
     self.palette_active = QPalette(self.palette())
     self.palette_inactive = QPalette(self.palette())
     b = self.palette().brush(QPalette.Active,QPalette.Highlight)
     self.palette_active.setBrush(QPalette.Inactive,QPalette.Highlight,b)
     # Set the cursor shape to IBeam -- no idea why this supposed default
     # inherited from QTextEdit, doesn't happen. But it doesn't.
     self.viewport().setCursor(Qt.IBeamCursor)
     # Hook up a slot to notice that the document has changed its
     # modification state.
     self.document().modificationChanged.connect(self.yikes)
     # Create our edit menu and stow it in the menu bar. Disable it.
     ed_menu = QMenu(C.ED_MENU_EDIT,self)
     ed_menu.addAction(C.ED_MENU_UNDO,self.undo,QKeySequence.Undo)
     ed_menu.addAction(C.ED_MENU_REDO,self.redo,QKeySequence.Redo)
     ed_menu.addSeparator()
     ed_menu.addAction(C.ED_MENU_CUT,self.cut,QKeySequence.Cut)
     ed_menu.addAction(C.ED_MENU_COPY,self.copy,QKeySequence.Copy)
     ed_menu.addAction(C.ED_MENU_PASTE,self.paste,QKeySequence.Paste)
     ed_menu.addSeparator()
     ed_menu.addAction(C.ED_MENU_FIND,self.find_action,QKeySequence.Find)
     ed_menu.addAction(C.ED_MENU_NEXT,self.find_next_action,QKeySequence.FindNext)
     self.edit_menu = mainwindow.get_menu_bar().addMenu(ed_menu)
     self.edit_menu.setVisible(False)
     # In order to get focus events, we need to set focus policy
     self.setFocusPolicy(Qt.StrongFocus)
开发者ID:B-Rich,项目名称:PPQT2,代码行数:48,代码来源:noteview.py

示例10: sizeHint

    def sizeHint(self, option, index):
        """QStyledItemDelegate.sizeHint implementation
        """
        options = QStyleOptionViewItem(option)
        self.initStyleOption(options, index)

        doc = QTextDocument()
        if self._font is not None:
            doc.setDefaultFont(self._font)
        doc.setDocumentMargin(1)
        #  bad long (multiline) strings processing doc.setTextWidth(options.rect.width())
        doc.setHtml(options.text)
        return QSize(doc.idealWidth(), doc.size().height())
开发者ID:hlamer,项目名称:enki,代码行数:13,代码来源:htmldelegate.py

示例11: sizeHint

 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,代码行数:7,代码来源:storywidget.py

示例12: formatText

    def formatText(self, text, _type):

        if not text:
            return text

            # if _type == "t2t":
            # text = self.runT2T(text)

            # elif _type == "txt":
            # text = text.replace("\n", "<br>")

        elif _type == "html":
            doc = QTextDocument()
            doc.setHtml(text)
            text = doc.toPlainText()
            # text = self.htmlBody(text)

        return text
开发者ID:TenKeyAngle,项目名称:manuskript,代码行数:18,代码来源:odt.py

示例13: sizeHint

    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,代码行数:8,代码来源:ActivitiesModel.py

示例14: sizeHint

    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,代码行数:8,代码来源:qt.py

示例15: test_highlighted

def test_highlighted(qtbot):
    """Make sure highlighting works.

    Note that with Qt 5.11.3 and > 5.12.1 we need to call setPlainText *after*
    creating the highlighter for highlighting to work. Ideally, we'd test
    whether CompletionItemDelegate._get_textdoc() works properly, but testing
    that is kind of hard, so we just test it in isolation here.
    """
    doc = QTextDocument()
    completiondelegate._Highlighter(doc, 'Hello', Qt.red)
    doc.setPlainText('Hello World')

    # Needed so the highlighting actually works.
    edit = QTextEdit()
    qtbot.addWidget(edit)
    edit.setDocument(doc)

    colors = [f.foreground().color() for f in doc.allFormats()]
    assert QColor('red') in colors
开发者ID:The-Compiler,项目名称:qutebrowser,代码行数:19,代码来源:test_completiondelegate.py


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