本文整理汇总了Python中PyQt4.QtGui.QTextDocument.setDefaultFont方法的典型用法代码示例。如果您正苦于以下问题:Python QTextDocument.setDefaultFont方法的具体用法?Python QTextDocument.setDefaultFont怎么用?Python QTextDocument.setDefaultFont使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QTextDocument
的用法示例。
在下文中一共展示了QTextDocument.setDefaultFont方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __render_fullname
# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import setDefaultFont [as 别名]
def __render_fullname(self, width, index):
fullname = index.data(self.FullnameRole).toPyObject()
doc = QTextDocument()
doc.setHtml("<b>%s</b>" % fullname)
doc.setDefaultFont(FULLNAME_FONT)
doc.setTextWidth(self.__calculate_text_width(width))
return doc
示例2: sizeHint
# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import setDefaultFont [as 别名]
def sizeHint(self, option, index):
text = index.model().data(index).toString()
document = QTextDocument()
document.setDefaultFont(option.font)
document.setHtml(text)
return QSize(document.idealWidth() + 5,
option.fontMetrics.height())
示例3: show
# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import setDefaultFont [as 别名]
def show(cursor, pos=None, num_lines=6):
"""Displays a tooltip showing part of the cursor's Document.
If the cursor has a selection, those blocks are displayed.
Otherwise, num_lines lines are displayed.
If pos is not given, the global mouse position is used.
"""
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() * .8)
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))
label = QLabel()
label.setPixmap(pix)
label.setStyleSheet("QLabel { border: 1px solid #777; }")
label.resize(size)
widgets.customtooltip.show(label, pos)
示例4: htmlCopy
# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import setDefaultFont [as 别名]
def htmlCopy(document, type='editor'):
"""Returns a new QTextDocument with highlighting set as HTML textcharformats."""
data = textformats.formatData(type)
doc = QTextDocument()
doc.setDefaultFont(data.font)
doc.setPlainText(document.toPlainText())
highlight(doc, HighlightFormats(data), ly.lex.state(documentinfo.mode(document)))
return doc
示例5: sizeHint
# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import setDefaultFont [as 别名]
def sizeHint(self, option, index):
fm = option.fontMetrics
if index.column() in (SRC_ADDR, DST_ADDR):
text = index.model().data(index).toString()
document = QTextDocument()
document.setDefaultFont(option.font)
document.setHtml(text)
#document.setPageSize(option.rect.size())
return QSize(document.idealWidth() + 5, 1.3 * fm.height())
return QItemDelegate.sizeHint(self, option, index)
示例6: __render_username
# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import setDefaultFont [as 别名]
def __render_username(self, width, index):
username_string = index.data(self.UsernameRole).toPyObject()
username = QTextDocument()
if username_string != '':
username.setHtml("<span style='color: #666;'>@%s</span>" % username_string)
else:
username.setHtml("<span style='color: #666;'></span>" % username_string)
username.setDefaultFont(USERNAME_FONT)
username.setTextWidth(self.__calculate_text_width(width))
return username
示例7: sizeHint
# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import setDefaultFont [as 别名]
def sizeHint(self, option, index):
fm = option.fontMetrics
if index.column() == TEU:
return QSize(fm.width("9,999,999"), fm.height())
if index.column() == DESCRIPTION:
text = index.model().data(index).toString()
document = QTextDocument()
document.setDefaultFont(option.font)
document.setHtml(text)
return QSize(document.idealWidth() + 5, fm.height())
return QStyledItemDelegate.sizeHint(self, option, index)
示例8: sizeHint
# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import setDefaultFont [as 别名]
def sizeHint(self, option, index):
"""
Reimplements the :meth:`QStyledItemDelegate.sizeHint` method.
"""
document = QTextDocument()
document.setDefaultFont(option.font)
data = index.model().data(index)
text = umbra.ui.common.getQVariantAsString(data)
self.__label.setText(text)
document.setHtml(text)
return QSize(document.idealWidth() + self.__indent, option.fontMetrics.height())
示例9: sizeHint
# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import setDefaultFont [as 别名]
def sizeHint( self, option, index ):
fm = option.fontMetrics
if index.column() in ( NOMBRE, TELEFONO, RUC, EMAIL ):
text = index.model().data( index ).toString()
document = QTextDocument()
document.setDefaultFont( option.font )
document.setHtml( text )
return QSize( document.idealWidth() + 5, fm.height() )
elif index.column() == ACTIVO:
return QSize( fm.width( "9" ), fm.height() )
else:
return QStyledItemDelegate.sizeHint( self, option, index )
示例10: documentForScript
# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import setDefaultFont [as 别名]
def documentForScript(self, script=0):
if type(script) != Script:
script = self.libraryList[script]
if script not in self._cachedDocuments:
doc = QTextDocument(self)
doc.setDocumentLayout(QPlainTextDocumentLayout(doc))
doc.setPlainText(script.script)
doc.setDefaultFont(QFont(self.defaultFont))
doc.highlighter = PythonSyntaxHighlighter(doc)
doc.modificationChanged[bool].connect(self.onModificationChanged)
doc.setModified(False)
self._cachedDocuments[script] = doc
return self._cachedDocuments[script]
示例11: sizeHint
# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import setDefaultFont [as 别名]
def sizeHint(self, option, index):
"""
This method is re-implemented because Description column is using HTML, it must return the exactly number of characters for
presentation purpose rather than the number of HTML raw characters.
"""
fm = option.fontMetrics
if index.column() == TEU:
return QSize(fm.width("9,999,999"), fm.height())
if index.column() == DESCRIPTION:
text = index.model().data(index).toString()
document = QTextDocument()
document.setDefaultFont(option.font)
document.setHtml(text)
return QSize(document.idealWidth() + 5, fm.height())
return QStyledItemDelegate.sizeHint(self, option, index)
示例12: html_copy
# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import setDefaultFont [as 别名]
def html_copy(cursor, scheme="editor", number_lines=False):
"""Return a new QTextDocument with highlighting set as HTML textcharformats.
The cursor is a cursor of a document.Document instance. If the cursor
has a selection, only the selection is put in the new document.
If number_lines is True, line numbers are added.
"""
data = textformats.formatData(scheme)
doc = QTextDocument()
doc.setDefaultFont(data.font)
doc.setPlainText(cursor.document().toPlainText())
if metainfo.info(cursor.document()).highlighting:
highlight(doc, mapping(data), ly.lex.state(documentinfo.mode(cursor.document())))
if cursor.hasSelection():
# cut out not selected text
start, end = cursor.selectionStart(), cursor.selectionEnd()
cur1 = QTextCursor(doc)
cur1.setPosition(start, QTextCursor.KeepAnchor)
cur2 = QTextCursor(doc)
cur2.setPosition(end)
cur2.movePosition(QTextCursor.End, QTextCursor.KeepAnchor)
cur2.removeSelectedText()
cur1.removeSelectedText()
if number_lines:
c = QTextCursor(doc)
f = QTextCharFormat()
f.setBackground(QColor("#eeeeee"))
if cursor.hasSelection():
num = cursor.document().findBlock(cursor.selectionStart()).blockNumber() + 1
last = cursor.document().findBlock(cursor.selectionEnd())
else:
num = 1
last = cursor.document().lastBlock()
lastnum = last.blockNumber() + 1
padding = len(format(lastnum))
block = doc.firstBlock()
while block.isValid():
c.setPosition(block.position())
c.setCharFormat(f)
c.insertText("{0:>{1}d} ".format(num, padding))
block = block.next()
num += 1
return doc
示例13: paint
# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import setDefaultFont [as 别名]
def paint(self, painter, option, index):
text = index.model().data(index, Qt.DisplayRole).toString()
palette = QApplication.palette()
document = QTextDocument()
document.setDefaultFont(option.font)
if option.state & QStyle.State_Selected:
document.setHtml(QString("<font color=%1>%2</font>")
.arg(palette.highlightedText().color().name())
.arg(text))
else:
document.setHtml(text)
painter.save()
color = (palette.highlight().color()
if option.state & QStyle.State_Selected
else QColor(index.model().data(index,
Qt.BackgroundColorRole)))
painter.fillRect(option.rect, color)
painter.translate(option.rect.x(), option.rect.y())
document.drawContents(painter)
painter.restore()
示例14: paint
# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import setDefaultFont [as 别名]
def paint(self, painter, option, index):
if index.column() in (SRC_ADDR, DST_ADDR):
text = index.model().data(index).toString()
palette = QApplication.palette()
document = QTextDocument()
document.setDefaultFont(option.font)
if option.state & QStyle.State_Selected:
document.setHtml("<font color=%s>%s</font>" %
(palette.highlightedText().color().name(), text))
color = palette.highlight().color()
else:
document.setHtml(text)
color = QColor(index.model().data(index, Qt.BackgroundColorRole))
#document.setPageSize(option.rect.size())
painter.save()
painter.fillRect(option.rect, color)
painter.translate(option.rect.x(), option.rect.y())
document.drawContents(painter)
painter.restore()
else:
QItemDelegate.paint(self, painter, option, index)
示例15: paint
# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import setDefaultFont [as 别名]
def paint(self, painter, option, index):
"""QStyledItemDelegate.paint implementation
"""
option.state &= ~QStyle.State_HasFocus # never draw focus rect
options = QStyleOptionViewItemV4(option)
self.initStyleOption(options,index)
style = QApplication.style() if options.widget is None else options.widget.style()
doc = QTextDocument()
doc.setDocumentMargin(1)
doc.setHtml(options.text)
if options.widget is not None:
doc.setDefaultFont(options.widget.font())
# bad long (multiline) strings processing doc.setTextWidth(options.rect.width())
options.text = ""
style.drawControl(QStyle.CE_ItemViewItem, options, painter);
ctx = QAbstractTextDocumentLayout.PaintContext()
# Highlighting 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, options)
painter.save()
painter.translate(textRect.topLeft())
"""Original example contained line
painter.setClipRect(textRect.translated(-textRect.topLeft()))
but text is drawn clipped with it on kubuntu 12.04
"""
doc.documentLayout().draw(painter, ctx)
painter.restore()