本文整理汇总了Python中PyQt4.QtGui.QTextDocument.setDocumentMargin方法的典型用法代码示例。如果您正苦于以下问题:Python QTextDocument.setDocumentMargin方法的具体用法?Python QTextDocument.setDocumentMargin怎么用?Python QTextDocument.setDocumentMargin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QTextDocument
的用法示例。
在下文中一共展示了QTextDocument.setDocumentMargin方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: paint
# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import setDocumentMargin [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)
# 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())
painter.setClipRect(textRect.translated(-textRect.topLeft()))
doc.documentLayout().draw(painter, ctx)
painter.restore()
示例2: sizeHint
# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import setDocumentMargin [as 别名]
def sizeHint(self, option, index):
"""QStyledItemDelegate.sizeHint implementation
"""
options = QStyleOptionViewItemV4(option)
self.initStyleOption(options,index)
doc = QTextDocument()
doc.setDocumentMargin(1)
# bad long (multiline) strings processing doc.setTextWidth(options.rect.width())
doc.setHtml(options.text)
return QSize(doc.idealWidth(), doc.size().height())
示例3: HtmlItemDelegate
# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import setDocumentMargin [as 别名]
class HtmlItemDelegate(QItemDelegate):
def __init__(self, parent):
QItemDelegate.__init__(self, parent)
self.document = QTextDocument(self)
self.document.setDocumentMargin(0)
self.hl_color = QApplication.palette().highlight().color()
self.hl_color = ",".join([repr(self.hl_color.red()), repr(self.hl_color.green()), repr(self.hl_color.blue())])
def drawDisplay(self, painter, option, rect, text):
point = rect.topLeft()
painter.translate(point)
if option.state & QStyle.State_Selected:
text = "<div style='background-color: rgb(%s)'>%s</div>" % (self.hl_color, text)
self.document.setHtml(text)
self.document.drawContents(painter)
painter.translate(-point)