def collect_block_and_char_format(): q = QTextDocument() q.setDefaultStyleSheet(CSS) css = dict(_CSS_BASE) css.pop("body") q.setHtml("") old = q.allFormats() html = "".join((f"<{k}>a</{k}>" for k in css.keys())) q.setHtml(html) charFormat = [] blockFormat = [] for f in q.allFormats(): if f in old: continue elif f.isCharFormat(): charFormat.append(f.toCharFormat()) elif f.isBlockFormat(): # pragma: no branch blockFormat.append(f.toBlockFormat()) return BlockFormat_(charFormat), BlockFormat_(blockFormat)
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