本文整理汇总了Python中PyQt4.QtGui.QTextDocument.documentLayout方法的典型用法代码示例。如果您正苦于以下问题:Python QTextDocument.documentLayout方法的具体用法?Python QTextDocument.documentLayout怎么用?Python QTextDocument.documentLayout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QTextDocument
的用法示例。
在下文中一共展示了QTextDocument.documentLayout方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: paint
# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import documentLayout [as 别名]
def paint(self, painter, option, index):
optionV4 = QStyleOptionViewItemV4(option)
self.initStyleOption(optionV4, index)
style = optionV4.widget.style() if optionV4.widget else QApplication.style()
doc = QTextDocument()
doc.setHtml(optionV4.text)
# painting item without text
optionV4.text = QString()
style.drawControl(QStyle.CE_ItemViewItem, optionV4, painter)
ctx = QAbstractTextDocumentLayout.PaintContext()
# Hilight text if item is selected
if optionV4.state & QStyle.State_Selected:
ctx.palette.setColor(QPalette.Text, optionV4.palette.color(QPalette.Active, QPalette.HighlightedText))
textRect = style.subElementRect(QStyle.SE_ItemViewItemText, optionV4)
painter.save()
painter.translate(textRect.topLeft())
painter.setClipRect(textRect.translated(-textRect.topLeft()))
doc.documentLayout().draw(painter, ctx)
painter.restore()
示例2: paint
# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import documentLayout [as 别名]
def paint(self, painter, option, index):
"""Render the delegate for the item."""
if index.column() != self._html_column:
return QStyledItemDelegate.paint(self, painter, option, index)
options = QStyleOptionViewItemV4(option)
self.initStyleOption(options, index)
if options.widget is None:
style = QApplication.style()
else:
style = options.widget.style()
doc = QTextDocument()
doc.setHtml(options.text)
options.text = ""
style.drawControl(QStyle.CE_ItemViewItem, options, painter)
ctx = QAbstractTextDocumentLayout.PaintContext()
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()
示例3: paint
# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import documentLayout [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()
示例4: paint
# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import documentLayout [as 别名]
def paint(self, painter, option, index):
options = QStyleOptionViewItemV4(option)
self.initStyleOption(options,index)
style = QApplication.style() if options.widget is None else options.widget.style()
doc = QTextDocument()
doc.setHtml(options.text)
options.text = ""
style.drawControl( QStyle.CE_ItemViewItem, options, painter)
ctx = QAbstractTextDocumentLayout.PaintContext()
textRect = style.subElementRect( QStyle.SE_ItemViewItemText, options )
# Highlighting text if item is selected
if options.state & QStyle.State_Selected :
# ctx.palette.setColor(
# QPalette.Text, options.palette.color(QPalette.Active, QPalette.HighlightedText)
# )
# painter.setBrush( options.palette.color( QPalette.Active, QPalette.Highlight ) )
# painter.setBrush( QColor( '#c1f48b' ) )
painter.setBrush( QColor( 0,180,0,30 ) )
painter.setPen( Qt.NoPen )
painter.drawRect( textRect )
elif options.state & QStyle.State_MouseOver :
# painter.setBrush( QColor( '#faffb8' ) )
# painter.setPen( Qt.NoPen )
# painter.drawRect( textRect )
painter.setBrush( QColor( 0,255,0,10 ) )
painter.setPen( Qt.NoPen )
painter.drawRect( textRect )
else:
painter.setPen( QColor( 0,0,0,10 ) )
painter.drawLine( textRect.bottomLeft(), textRect.bottomRight() )
painter.save()
painter.translate(textRect.topLeft())
painter.setClipRect(textRect.translated(-textRect.topLeft()))
doc.documentLayout().draw(painter, ctx)
painter.restore()
示例5: MessageItemDelegate
# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import documentLayout [as 别名]
#.........这里部分代码省略.........
mouseOver = (int(option.state) & int(QStyle.State_MouseOver)) != 0
if mouseOver:
self.mouseOverDocument = QTextDocument()
self.mouseOverDocument.setHtml(text)
self.mouseOverDocument.setTextWidth(self._preferredMessageWidth(option.rect.width()))
self.mouseOverDocumentRow = modelIndex.row()
self.lastTextPos = textRect.topLeft()
self.mouseOverOption = option
# draw decoration
painter.translate(textRect.topLeft())
statusIcon = modelIndex.data(ChatMessagesModel.STATUS_ICON_ROLE)
if statusIcon != None and not statusIcon.isNull():
statusIcon = QIcon(statusIcon)
if rightAligned:
statusIcon.paint(painter, textRect.size().width() - 19, 8, 16, 16, Qt.AlignCenter)
else:
statusIcon.paint(painter, 3, 8, 16, 16, Qt.AlignCenter)
# draw message
painter.restore()
painter.save()
painter.setRenderHint(QPainter.Antialiasing)
painter.translate(messageRect.topLeft())
if not editing:
painter.setBrush(self._ownBrush if rightAligned else self._otherBrush)
painter.setPen(self._ownPenColor if rightAligned else self._otherPenColor)
painter.drawRoundedRect(QRectF(QPointF(0, 0.5),
QSizeF(self.document.idealWidth(),
self.document.size().height() - 1.)),
7, 7)
painter.setClipRect(textRect.translated(-textRect.topLeft()))
if not editing:
self.document.documentLayout().draw(painter, ctx)
painter.restore()
startEditing = pyqtSignal(QModelIndex)
def shouldStartEditAt(self, eventPos, modelIndex):
option = QStyleOptionViewItemV4()
option.initFrom(self.parent())
option.rect.setHeight(32)
self.initStyleOption(option, modelIndex)
if modelIndex.row() != self.mouseOverDocumentRow:
# TODO reset document
self.logger.warning("shouldStartEditAt(): wrong mouse over document")
return False
messageRect = self._getMessageRect(self.mouseOverOption, self.mouseOverDocument, modelIndex)
anchorPos = QPointF(eventPos) - QPointF(messageRect.topLeft())
anchor = self.mouseOverDocument.documentLayout().anchorAt(anchorPos)
if anchor != "":
return False
return messageRect.contains(eventPos)
def editorEvent(self, event, _model, option_, modelIndex):
if self._column and modelIndex.column() != self._column:
return False
option = QStyleOptionViewItemV4(option_)
self.initStyleOption(option, modelIndex)
text = QString(option.text)
if not text:
self.parent().unsetCursor()
return False