本文整理汇总了Python中AnyQt.QtWidgets.QLabel.textFormat方法的典型用法代码示例。如果您正苦于以下问题:Python QLabel.textFormat方法的具体用法?Python QLabel.textFormat怎么用?Python QLabel.textFormat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyQt.QtWidgets.QLabel
的用法示例。
在下文中一共展示了QLabel.textFormat方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MessageWidget
# 需要导入模块: from AnyQt.QtWidgets import QLabel [as 别名]
# 或者: from AnyQt.QtWidgets.QLabel import textFormat [as 别名]
class MessageWidget(QWidget):
"""
A widget displaying a simple message to the user.
This is an alternative to a full QMessageBox intended for inline
modeless messages.
[[icon] {Message text} (Ok) (Cancel)]
"""
#: Emitted when a button with the AcceptRole is clicked
accepted = Signal()
#: Emitted when a button with the RejectRole is clicked
rejected = Signal()
#: Emitted when a button with the HelpRole is clicked
helpRequested = Signal()
#: Emitted when a button is clicked
clicked = Signal(QAbstractButton)
class StandardButton(enum.IntEnum):
NoButton, Ok, Close, Help = 0x0, 0x1, 0x2, 0x4
NoButton, Ok, Close, Help = list(StandardButton)
class ButtonRole(enum.IntEnum):
InvalidRole, AcceptRole, RejectRole, HelpRole = 0, 1, 2, 3
InvalidRole, AcceptRole, RejectRole, HelpRole = list(ButtonRole)
_Button = namedtuple("_Button", ["button", "role", "stdbutton"])
def __init__(self, parent=None, icon=QIcon(), text="", wordWrap=False,
textFormat=Qt.AutoText, standardButtons=NoButton, **kwargs):
super().__init__(parent, **kwargs)
self.__text = text
self.__icon = QIcon()
self.__wordWrap = wordWrap
self.__standardButtons = MessageWidget.NoButton
self.__buttons = []
layout = QHBoxLayout()
layout.setContentsMargins(8, 0, 8, 0)
self.__iconlabel = QLabel(objectName="icon-label")
self.__iconlabel.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
self.__textlabel = QLabel(objectName="text-label", text=text,
wordWrap=wordWrap, textFormat=textFormat)
if sys.platform == "darwin":
self.__textlabel.setAttribute(Qt.WA_MacSmallSize)
layout.addWidget(self.__iconlabel)
layout.addWidget(self.__textlabel)
self.setLayout(layout)
self.setIcon(icon)
self.setStandardButtons(standardButtons)
def setText(self, text):
"""
Set the current message text.
:type message: str
"""
if self.__text != text:
self.__text = text
self.__textlabel.setText(text)
def text(self):
"""
Return the current message text.
:rtype: str
"""
return self.__text
def setIcon(self, icon):
"""
Set the message icon.
:type icon: QIcon | QPixmap | QString | QStyle.StandardPixmap
"""
if isinstance(icon, QStyle.StandardPixmap):
icon = self.style().standardIcon(icon)
else:
icon = QIcon(icon)
if self.__icon != icon:
self.__icon = QIcon(icon)
if not self.__icon.isNull():
size = self.style().pixelMetric(
QStyle.PM_SmallIconSize, None, self)
pm = self.__icon.pixmap(QSize(size, size))
else:
pm = QPixmap()
self.__iconlabel.setPixmap(pm)
self.__iconlabel.setVisible(not pm.isNull())
def icon(self):
"""
Return the current icon.
#.........这里部分代码省略.........