本文整理汇总了Python中PyQt5.QtGui.QTextDocument.size方法的典型用法代码示例。如果您正苦于以下问题:Python QTextDocument.size方法的具体用法?Python QTextDocument.size怎么用?Python QTextDocument.size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtGui.QTextDocument
的用法示例。
在下文中一共展示了QTextDocument.size方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: pixmap
# 需要导入模块: from PyQt5.QtGui import QTextDocument [as 别名]
# 或者: from PyQt5.QtGui.QTextDocument import size [as 别名]
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
示例2: sizeHint
# 需要导入模块: from PyQt5.QtGui import QTextDocument [as 别名]
# 或者: from PyQt5.QtGui.QTextDocument import size [as 别名]
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())
示例3: sizeHint
# 需要导入模块: from PyQt5.QtGui import QTextDocument [as 别名]
# 或者: from PyQt5.QtGui.QTextDocument import size [as 别名]
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()))
示例4: sizeHint
# 需要导入模块: from PyQt5.QtGui import QTextDocument [as 别名]
# 或者: from PyQt5.QtGui.QTextDocument import size [as 别名]
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())
示例5: sizeHint
# 需要导入模块: from PyQt5.QtGui import QTextDocument [as 别名]
# 或者: from PyQt5.QtGui.QTextDocument import size [as 别名]
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())
示例6: sizeHint
# 需要导入模块: from PyQt5.QtGui import QTextDocument [as 别名]
# 或者: from PyQt5.QtGui.QTextDocument import size [as 别名]
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())
示例7: CompletionItemDelegate
# 需要导入模块: from PyQt5.QtGui import QTextDocument [as 别名]
# 或者: from PyQt5.QtGui.QTextDocument import size [as 别名]
#.........这里部分代码省略.........
text_option.setTextDirection(self._opt.direction)
text_option.setAlignment(QStyle.visualAlignment(
self._opt.direction, self._opt.displayAlignment))
if self._doc is not None:
self._doc.deleteLater()
self._doc = QTextDocument(self)
self._doc.setDefaultFont(self._opt.font)
self._doc.setDefaultTextOption(text_option)
self._doc.setDocumentMargin(2)
assert _cached_stylesheet is not None
self._doc.setDefaultStyleSheet(_cached_stylesheet)
if index.parent().isValid():
view = self.parent()
pattern = view.pattern
columns_to_filter = index.model().columns_to_filter(index)
if index.column() in columns_to_filter and pattern:
repl = r'<span class="highlight">\g<0></span>'
pat = html.escape(re.escape(pattern)).replace(r'\ ', r'|')
txt = html.escape(self._opt.text)
text = re.sub(pat, repl, txt, flags=re.IGNORECASE)
self._doc.setHtml(text)
else:
self._doc.setPlainText(self._opt.text)
else:
self._doc.setHtml(
'<span style="font: {};">{}</span>'.format(
html.escape(config.val.fonts.completion.category),
html.escape(self._opt.text)))
def _draw_focus_rect(self):
"""Draw the focus rectangle of an ItemViewItem."""
state = self._opt.state
if not state & QStyle.State_HasFocus:
return
o = self._opt
o.rect = self._style.subElementRect(
self._style.SE_ItemViewItemFocusRect, self._opt, self._opt.widget)
o.state |= QStyle.State_KeyboardFocusChange | QStyle.State_Item
qtutils.ensure_valid(o.rect)
if state & QStyle.State_Enabled:
cg = QPalette.Normal
else:
cg = QPalette.Disabled
if state & QStyle.State_Selected:
role = QPalette.Highlight
else:
role = QPalette.Window
o.backgroundColor = self._opt.palette.color(cg, role)
self._style.drawPrimitive(QStyle.PE_FrameFocusRect, o, self._painter,
self._opt.widget)
def sizeHint(self, option, index):
"""Override sizeHint of QStyledItemDelegate.
Return the cell size based on the QTextDocument size, but might not
work correctly yet.
Args:
option: const QStyleOptionViewItem & option
index: const QModelIndex & index
Return:
A QSize with the recommended size.
"""
value = index.data(Qt.SizeHintRole)
if value is not None:
return value
self._opt = QStyleOptionViewItem(option)
self.initStyleOption(self._opt, index)
self._style = self._opt.widget.style()
self._get_textdoc(index)
docsize = self._doc.size().toSize()
size = self._style.sizeFromContents(QStyle.CT_ItemViewItem, self._opt,
docsize, self._opt.widget)
qtutils.ensure_valid(size)
return size + QSize(10, 3)
def paint(self, painter, option, index):
"""Override the QStyledItemDelegate paint function.
Args:
painter: QPainter * painter
option: const QStyleOptionViewItem & option
index: const QModelIndex & index
"""
self._painter = painter
self._painter.save()
self._opt = QStyleOptionViewItem(option)
self.initStyleOption(self._opt, index)
self._style = self._opt.widget.style()
self._draw_background()
self._draw_icon()
self._draw_text(index)
self._draw_focus_rect()
self._painter.restore()