本文整理汇总了Python中PyQt4.QtCore.Qt.mightBeRichText方法的典型用法代码示例。如果您正苦于以下问题:Python Qt.mightBeRichText方法的具体用法?Python Qt.mightBeRichText怎么用?Python Qt.mightBeRichText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtCore.Qt
的用法示例。
在下文中一共展示了Qt.mightBeRichText方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getTooltipValue
# 需要导入模块: from PyQt4.QtCore import Qt [as 别名]
# 或者: from PyQt4.QtCore.Qt import mightBeRichText [as 别名]
def getTooltipValue( value ):
""" Takes a potentially multilined string and converts it to
the form suitable for tooltips """
value = str( value )
if Qt.mightBeRichText( value ):
tooltipValue = str( Qt.escape( value ) )
else:
tooltipValue = value
lines = tooltipValue.splitlines()
lineCount = len( lines )
if lineCount > 1:
value = ""
index = 0
for line in lines:
if index >= 5: # First 5 lines only
break
if index > 0:
value += "\n"
if len( line ) > 128:
value += line[ : 128 ] + "<...>"
else:
value += line
index += 1
if lineCount > 5:
value += "\n<...>"
elif lineCount == 1:
if len( lines[ 0 ] ) > 128:
value = lines[ 0 ][ : 128 ] + "<...>"
else:
value = lines[ 0 ]
return value
示例2: drawContents
# 需要导入模块: from PyQt4.QtCore import Qt [as 别名]
# 或者: from PyQt4.QtCore.Qt import mightBeRichText [as 别名]
def drawContents(self, painter):
"""
Reimplementation of drawContents to limit the drawing
inside `textRext`.
"""
painter.setPen(self.__color)
painter.setFont(self.font())
if self.__textRect:
rect = self.__textRect
else:
rect = self.rect().adjusted(5, 5, -5, -5)
if Qt.mightBeRichText(self.__message):
doc = QTextDocument()
doc.setHtml(self.__message)
doc.setTextWidth(rect.width())
cursor = QTextCursor(doc)
cursor.select(QTextCursor.Document)
fmt = QTextBlockFormat()
fmt.setAlignment(self.__alignment)
cursor.mergeBlockFormat(fmt)
painter.save()
painter.translate(rect.topLeft())
doc.drawContents(painter)
painter.restore()
else:
painter.drawText(rect, self.__alignment, self.__message)