本文整理汇总了Python中PyQt5.QtGui.QTextDocument.allFormats方法的典型用法代码示例。如果您正苦于以下问题:Python QTextDocument.allFormats方法的具体用法?Python QTextDocument.allFormats怎么用?Python QTextDocument.allFormats使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtGui.QTextDocument
的用法示例。
在下文中一共展示了QTextDocument.allFormats方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_highlighted
# 需要导入模块: from PyQt5.QtGui import QTextDocument [as 别名]
# 或者: from PyQt5.QtGui.QTextDocument import allFormats [as 别名]
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