本文整理汇总了Python中AnyQt.QtWidgets.QLabel.isVisible方法的典型用法代码示例。如果您正苦于以下问题:Python QLabel.isVisible方法的具体用法?Python QLabel.isVisible怎么用?Python QLabel.isVisible使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyQt.QtWidgets.QLabel
的用法示例。
在下文中一共展示了QLabel.isVisible方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MessagesWidget
# 需要导入模块: from AnyQt.QtWidgets import QLabel [as 别名]
# 或者: from AnyQt.QtWidgets.QLabel import isVisible [as 别名]
#.........这里部分代码省略.........
def __update(self):
"""
Update the current display state.
"""
self.ensurePolished()
summary = self.summarize()
icon = message_icon(summary)
self.__iconwidget.setIcon(icon)
self.__iconwidget.setVisible(not (summary.isEmpty() or icon.isNull()))
self.__textlabel.setTextFormat(summary.textFormat)
self.__textlabel.setText(summary.text)
self.__textlabel.setVisible(bool(summary.text))
messages = [m for m in self.__messages.values() if not m.isEmpty()]
if messages:
messages = sorted(messages, key=attrgetter("severity"),
reverse=True)
fulltext = "<hr/>".join(m.asHtml() for m in messages)
else:
fulltext = ""
self.__fulltext = fulltext
self.setToolTip(self.__styled(self.__defaultStyleSheet, fulltext))
def is_short(m):
return not (m.informativeText or m.detailedText)
if not messages or len(messages) == 1 and is_short(messages[0]):
self.__popuptext = ""
else:
self.__popuptext = fulltext
self.__popupicon.setVisible(bool(self.__popuptext))
self.layout().activate()
def mousePressEvent(self, event):
if event.button() == Qt.LeftButton:
if self.__popuptext:
popup = QMenu(self)
label = QLabel(
self, textInteractionFlags=Qt.TextBrowserInteraction,
openExternalLinks=self.__openExternalLinks,
)
label.setText(self.__styled(self.__defaultStyleSheet,
self.__popuptext))
label.linkActivated.connect(self.linkActivated)
label.linkHovered.connect(self.linkHovered)
action = QWidgetAction(popup)
action.setDefaultWidget(label)
popup.addAction(action)
popup.popup(event.globalPos(), action)
event.accept()
return
else:
super().mousePressEvent(event)
def enterEvent(self, event):
super().enterEvent(event)
self.update()
def leaveEvent(self, event):
super().leaveEvent(event)
self.update()
def changeEvent(self, event):
super().changeEvent(event)
self.update()
def paintEvent(self, event):
opt = QStyleOption()
opt.initFrom(self)
if not self.__popupicon.isVisible():
return
if not (opt.state & QStyle.State_MouseOver or
opt.state & QStyle.State_HasFocus):
return
palette = opt.palette # type: QPalette
if opt.state & QStyle.State_HasFocus:
pen = QPen(palette.color(QPalette.Highlight))
else:
pen = QPen(palette.color(QPalette.Dark))
if self.__fulltext and \
opt.state & QStyle.State_MouseOver and \
opt.state & QStyle.State_Active:
g = QLinearGradient()
g.setCoordinateMode(QLinearGradient.ObjectBoundingMode)
base = palette.color(QPalette.Window)
base.setAlpha(90)
g.setColorAt(0, base.lighter(200))
g.setColorAt(0.6, base)
g.setColorAt(1.0, base.lighter(200))
brush = QBrush(g)
else:
brush = QBrush(Qt.NoBrush)
p = QPainter(self)
p.setBrush(brush)
p.setPen(pen)
p.drawRect(opt.rect.adjusted(0, 0, -1, -1))