本文整理汇总了Python中PyQt5.QtGui.QTextDocument方法的典型用法代码示例。如果您正苦于以下问题:Python QtGui.QTextDocument方法的具体用法?Python QtGui.QTextDocument怎么用?Python QtGui.QTextDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtGui
的用法示例。
在下文中一共展示了QtGui.QTextDocument方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_highlighted
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QTextDocument [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
示例2: get_chapter_content
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QTextDocument [as 别名]
def get_chapter_content(self, chapter_file):
this_file = self.find_file(chapter_file)
if this_file:
chapter_content = self.zip_file.read(this_file).decode()
# Generate a None return for a blank chapter
# These will be removed from the contents later
contentDocument = QtGui.QTextDocument(None)
contentDocument.setHtml(chapter_content)
contentText = contentDocument.toPlainText().replace('\n', '')
if contentText == '':
chapter_content = None
return chapter_content
else:
return 'Possible parse error: ' + chapter_file
示例3: get_max_left_label_width
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QTextDocument [as 别名]
def get_max_left_label_width(self):
doc = QTextDocument(self)
doc.setDocumentMargin(0)
doc.setDefaultFont(self.lblOwnerKey.font())
doc.setHtml('Test')
def get_lbl_text_width(lbl):
nonlocal doc
doc.setHtml(lbl.text())
return int(doc.size().width() + 5)
w = max(get_lbl_text_width(self.lblName),
get_lbl_text_width(self.lblIP),
get_lbl_text_width(self.lblCollateral),
get_lbl_text_width(self.lblCollateralTxHash),
get_lbl_text_width(self.lblDMNTxHash),
get_lbl_text_width(self.lblOwnerKey),
get_lbl_text_width(self.lblOperatorKey),
get_lbl_text_width(self.lblVotingKey))
return w
示例4: paint
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QTextDocument [as 别名]
def paint(self, painter, option, index):
options = QtWidgets.QStyleOptionViewItem(option)
self.initStyleOption(options, index)
style = QtGui.QApplication.style() if options.widget is None\
else options.widget.style()
doc = QtGui.QTextDocument()
doc.setHtml(options.text)
options.text = ""
style.drawControl(QtGui.QStyle.CE_ItemViewItem, options, painter)
ctx = QtGui.QAbstractTextDocumentLayout.PaintContext()
textRect = style.subElementRect(
QtGui.QStyle.SE_ItemViewItemText, options, options.widget)
painter.save()
painter.translate(textRect.topLeft())
painter.setClipRect(textRect.translated(-textRect.topLeft()))
doc.documentLayout().draw(painter, ctx)
painter.restore()
示例5: heightForWidth
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QTextDocument [as 别名]
def heightForWidth(self, width):
margins = self.contentsMargins()
if width >= margins.left() + margins.right():
document_width = width - margins.left() - margins.right()
else:
# If specified width can't even fit the margin, there's no space left for the document
document_width = 0
# Cloning the whole document only to check its size at different width seems wasteful
# but apparently it's the only and preferred way to do this in Qt >= 4. QTextDocument does not
# provide any means to get height for specified width (as some QWidget subclasses do).
# Neither does QTextEdit. In Qt3 Q3TextEdit had working implementation of heightForWidth()
# but it was allegedly just a hack and was removed.
#
# The performance probably won't be a problem here because the application is meant to
# work with a lot of small notes rather than few big ones. And there's usually only one
# editor that needs to be dynamically resized - the one having focus.
document = self.document().clone()
document.setTextWidth(document_width)
return margins.top() + document.size().height() + margins.bottom()
示例6: init_print
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QTextDocument [as 别名]
def init_print(self, linenos=True, style="default"):
app = QApplication([]) # noqa
doc = QTextDocument()
doc.setHtml(
self.highlight_file(linenos=linenos, style=style)
)
printer = QPrinter()
printer.setOutputFileName(self.pdf_file)
printer.setOutputFormat(QPrinter.PdfFormat)
page_size_dict = {"a2": QPrinter.A2, "a3": QPrinter.A3, "a4": QPrinter.A4, "letter": QPrinter.Letter}
printer.setPageSize(page_size_dict.get(self.size.lower(), QPrinter.A4))
printer.setPageMargins(15, 15, 15, 15, QPrinter.Millimeter)
doc.print_(printer)
logging.info("PDF created at %s" % (self.pdf_file))
示例7: __init__
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QTextDocument [as 别名]
def __init__(self, parent=None):
super().__init__()
self.doc = Qg.QTextDocument(self)
示例8: reload_java_sources
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QTextDocument [as 别名]
def reload_java_sources(self):
"""Reload completely the sources by asking Androguard
to decompile it again. Useful when:
- an element has been renamed to propagate the info
- the current tab is changed because we do not know what user
did since then, so we need to propagate previous changes as well
"""
log.debug("Getting sources for %s" % self.current_class)
lines = [("COMMENTS", [(
"COMMENT", "// filename:%s\n// digest:%s\n\n" % (
self.current_filename, self.current_digest))])]
method_info_buff = ""
for method in self.current_class.get_methods():
method_info_buff += "// " + str(method) + "\n"
lines.append(("COMMENTS", [(
"COMMENT", method_info_buff + "\n\n")]))
lines.extend(self.current_class.get_source_ext())
# TODO: delete doc when tab is closed? not deleted by "self" :(
if hasattr(self, "doc"):
del self.doc
self.doc = SourceDocument(parent=self, lines=lines)
self.setDocument(self.doc)
# No need to save hightlighter. highlighBlock will automatically be called
# because we passed the QTextDocument to QSyntaxHighlighter constructor
MyHighlighter(self.doc, lexer=JavaLexer())
示例9: test_highlight
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QTextDocument [as 别名]
def test_highlight(pat, txt, segments):
doc = QTextDocument(txt)
highlighter = completiondelegate._Highlighter(doc, pat, Qt.red)
highlighter.setFormat = mock.Mock()
highlighter.highlightBlock(txt)
highlighter.setFormat.assert_has_calls([
mock.call(s[0], s[1], mock.ANY) for s in segments
])
示例10: generate_position
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QTextDocument [as 别名]
def generate_position(self, is_read=False):
total_chapters = len(self.metadata['content'])
current_chapter = 1
if is_read:
current_chapter = total_chapters
# Generate block count @ time of first read
# Blocks are indexed from 0 up
blocks_per_chapter = []
total_blocks = 0
if not self.are_we_doing_images_only:
for i in self.metadata['content']:
textDocument = QtGui.QTextDocument(None)
textDocument.setHtml(i)
block_count = textDocument.blockCount()
blocks_per_chapter.append(block_count)
total_blocks += block_count
self.metadata['position'] = {
'current_chapter': current_chapter,
'total_chapters': total_chapters,
'blocks_per_chapter': blocks_per_chapter,
'total_blocks': total_blocks,
'is_read': is_read,
'current_block': 0,
'cursor_position': 0}
示例11: setupUi
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QTextDocument [as 别名]
def setupUi(self):
Ui_TransactionDlg.setupUi(self, self)
self.setWindowTitle('Transaction')
self.chb_word_wrap.setChecked(app_cache.get_value(CACHE_ITEM_DETAILS_WORD_WRAP, False, bool))
self.apply_word_wrap(self.chb_word_wrap.isChecked())
self.edt_recipients.viewport().setAutoFillBackground(False)
if sys.platform == 'win32':
self.base_font_size = '11'
self.title_font_size = '15'
elif sys.platform == 'linux':
self.base_font_size = '11'
self.title_font_size = '17'
else: # mac
self.base_font_size = '13'
self.title_font_size = '20'
self.edt_raw_transaction.setStyleSheet(f'font: {self.base_font_size}pt "Courier New";')
doc = QTextDocument(self)
doc.setDocumentMargin(0)
doc.setHtml(f'<span style=" font-size:{self.title_font_size}pt;white-space:nowrap">AAAAAAAAAAAAAAAAAA')
self.edt_recipients.setStyle(ProxyStyleNoFocusRect())
default_width = int(doc.size().width()) * 3
default_height = int(default_width / 2)
app_cache.restore_window_size(self, default_width=default_width, default_height=default_height)
self.prepare_tx_view()
示例12: sizeHint
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QTextDocument [as 别名]
def sizeHint(self, option, index):
options = QtWidgets.QStyleOptionViewItem(option)
self.initStyleOption(options, index)
doc = QtGui.QTextDocument()
doc.setHtml(options.text)
doc.setTextWidth(options.rect.width())
return QtCore.QSize(doc.idealWidth(), doc.size().height())
示例13: __init__
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QTextDocument [as 别名]
def __init__(self, parent=None):
super().__init__(parent)
help_content = QTextDocument()
help_content.setHtml(HELP_CONTENT)
self.setOpenExternalLinks(True)
self.setDocument(help_content)
示例14: _linetool_annotate_point
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QTextDocument [as 别名]
def _linetool_annotate_point(self, point, idx):
annotation = QgsTextAnnotation()
c = QTextDocument()
html = "<strong>" + str(idx) + "</strong>"
c.setHtml(html)
annotation.setDocument(c)
annotation.setFrameSize(QSizeF(27, 20))
annotation.setFrameOffsetFromReferencePoint(QPointF(5, 5))
annotation.setMapPosition(point)
annotation.setMapPositionCrs(self.map_crs)
return QgsMapCanvasAnnotationItem(annotation, self._iface.mapCanvas()).annotation()
示例15: __init__
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QTextDocument [as 别名]
def __init__(self, parent=None):
super(TableDelegate, self).__init__(parent)
self.doc = QTextDocument(self)