本文整理匯總了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)