本文整理汇总了Python中AnyQt.QtWidgets.QLabel.setVisible方法的典型用法代码示例。如果您正苦于以下问题:Python QLabel.setVisible方法的具体用法?Python QLabel.setVisible怎么用?Python QLabel.setVisible使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyQt.QtWidgets.QLabel
的用法示例。
在下文中一共展示了QLabel.setVisible方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MessagesWidget
# 需要导入模块: from AnyQt.QtWidgets import QLabel [as 别名]
# 或者: from AnyQt.QtWidgets.QLabel import setVisible [as 别名]
#.........这里部分代码省略.........
Returns
-------
messages: `List[Message]`
"""
return list(self.__messages.values())
def summarize(self):
# type: () -> Message
"""
Summarize all the messages into a single message.
"""
messages = [m for m in self.__messages.values() if not m.isEmpty()]
if messages:
return summarize(messages)
else:
return Message()
@staticmethod
def __styled(css, html):
# Prepend css style sheet before a html fragment.
if css.strip():
return "<style>\n" + escape(css) + "\n</style>\n" + html
else:
return html
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,
示例2: MessageWidget
# 需要导入模块: from AnyQt.QtWidgets import QLabel [as 别名]
# 或者: from AnyQt.QtWidgets.QLabel import setVisible [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.
#.........这里部分代码省略.........
示例3: PreviewBrowser
# 需要导入模块: from AnyQt.QtWidgets import QLabel [as 别名]
# 或者: from AnyQt.QtWidgets.QLabel import setVisible [as 别名]
class PreviewBrowser(QWidget):
"""A Preview Browser for recent/premade scheme selection.
"""
# Emitted when the current previewed item changes
currentIndexChanged = Signal(int)
# Emitted when an item is double clicked in the preview list.
activated = Signal(int)
def __init__(self, *args, heading="", previewMargins=12, **kwargs):
super().__init__(*args)
self.__model = None
self.__currentIndex = -1
self.__template = DESCRIPTION_TEMPLATE
self.__margin = previewMargins
self.__setupUi()
self.setHeading(heading)
def __setupUi(self):
vlayout = QVBoxLayout()
vlayout.setContentsMargins(0, 0, 0, 0)
top_layout = QVBoxLayout(objectName="top-layout")
margin = self.__margin
top_layout.setContentsMargins(margin, margin, margin, margin)
# Optional heading label
self.__heading = QLabel(
self, objectName="heading", visible=False
)
# Horizontal row with full text description and a large preview
# image.
hlayout = QHBoxLayout()
hlayout.setContentsMargins(0, 0, 0, 0)
self.__label = QLabel(
self, objectName="description-label",
wordWrap=True, alignment=Qt.AlignTop | Qt.AlignLeft
)
self.__label.setWordWrap(True)
self.__label.setFixedSize(220, PREVIEW_SIZE[1])
self.__label.setMinimumWidth(PREVIEW_SIZE[0] // 2)
self.__label.setMaximumHeight(PREVIEW_SIZE[1])
self.__image = QSvgWidget(self, objectName="preview-image")
self.__image.setFixedSize(*PREVIEW_SIZE)
self.__imageFrame = DropShadowFrame(self)
self.__imageFrame.setWidget(self.__image)
hlayout.addWidget(self.__label)
hlayout.addWidget(self.__image)
# Path text below the description and image
path_layout = QHBoxLayout()
path_layout.setContentsMargins(0, 0, 0, 0)
path_label = QLabel("<b>{0!s}</b>".format(self.tr("Path:")), self,
objectName="path-label")
self.__path = TextLabel(self, objectName="path-text")
path_layout.addWidget(path_label)
path_layout.addWidget(self.__path)
top_layout.addWidget(self.__heading)
top_layout.addLayout(hlayout)
top_layout.addLayout(path_layout)
vlayout.addLayout(top_layout)
# An list view with small preview icons.
self.__previewList = LinearIconView(
objectName="preview-list-view",
wordWrap=True
)
self.__previewList.doubleClicked.connect(self.__onDoubleClicked)
vlayout.addWidget(self.__previewList)
self.setLayout(vlayout)
def setHeading(self, text):
self.__heading.setVisible(bool(text))
self.__heading.setText(text)
def setPreviewMargins(self, margin):
# type: (int) -> None
"""
Set the left, top and right margins of the top widget part (heading
and description)
Parameters
----------
margin : int
Margin
"""
if margin != self.__margin:
layout = self.layout().itemAt(0).layout()
assert isinstance(layout, QVBoxLayout)
assert layout.objectName() == "top-layout"
layout.setContentsMargins(margin, margin, margin, 0)
def setModel(self, model):
#.........这里部分代码省略.........
示例4: WelcomeDialog
# 需要导入模块: from AnyQt.QtWidgets import QLabel [as 别名]
# 或者: from AnyQt.QtWidgets.QLabel import setVisible [as 别名]
class WelcomeDialog(QDialog):
"""
A welcome widget shown at startup presenting a series
of buttons (actions) for a beginner to choose from.
"""
triggered = Signal(QAction)
def __init__(self, *args, **kwargs):
showAtStartup = kwargs.pop("showAtStartup", True)
feedbackUrl = kwargs.pop("feedbackUrl", "")
super().__init__(*args, **kwargs)
self.__triggeredAction = None
self.__showAtStartupCheck = None
self.__mainLayout = None
self.__feedbackUrl = None
self.__feedbackLabel = None
self.setupUi()
self.setFeedbackUrl(feedbackUrl)
self.setShowAtStartup(showAtStartup)
def setupUi(self):
self.setLayout(QVBoxLayout())
self.layout().setContentsMargins(0, 0, 0, 0)
self.layout().setSpacing(0)
self.__mainLayout = QVBoxLayout()
self.__mainLayout.setContentsMargins(0, 40, 0, 40)
self.__mainLayout.setSpacing(65)
self.layout().addLayout(self.__mainLayout)
self.setStyleSheet(WELCOME_WIDGET_BUTTON_STYLE)
bottom_bar = QWidget(objectName="bottom-bar")
bottom_bar_layout = QHBoxLayout()
bottom_bar_layout.setContentsMargins(20, 10, 20, 10)
bottom_bar.setLayout(bottom_bar_layout)
bottom_bar.setSizePolicy(QSizePolicy.MinimumExpanding,
QSizePolicy.Maximum)
self.__showAtStartupCheck = QCheckBox(
self.tr("Show at startup"), bottom_bar, checked=False
)
self.__feedbackLabel = QLabel(
textInteractionFlags=Qt.TextBrowserInteraction,
openExternalLinks=True,
visible=False,
)
bottom_bar_layout.addWidget(
self.__showAtStartupCheck, alignment=Qt.AlignVCenter | Qt.AlignLeft
)
bottom_bar_layout.addWidget(
self.__feedbackLabel, alignment=Qt.AlignVCenter | Qt.AlignRight
)
self.layout().addWidget(bottom_bar, alignment=Qt.AlignBottom,
stretch=1)
self.setSizeGripEnabled(False)
self.setFixedSize(620, 390)
def setShowAtStartup(self, show):
"""
Set the 'Show at startup' check box state.
"""
if self.__showAtStartupCheck.isChecked() != show:
self.__showAtStartupCheck.setChecked(show)
def showAtStartup(self):
"""
Return the 'Show at startup' check box state.
"""
return self.__showAtStartupCheck.isChecked()
def setFeedbackUrl(self, url):
# type: (str) -> None
"""
Set an 'feedback' url. When set a link is displayed in the bottom row.
"""
self.__feedbackUrl = url
if url:
text = self.tr("Help us improve!")
self.__feedbackLabel.setText(
'<a href="{url}">{text}</a>'.format(url=url, text=escape(text))
)
else:
self.__feedbackLabel.setText("")
self.__feedbackLabel.setVisible(bool(url))
def addRow(self, actions, background="light-orange"):
"""Add a row with `actions`.
"""
count = self.__mainLayout.count()
self.insertRow(count, actions, background)
def insertRow(self, index, actions, background="light-orange"):
"""Insert a row with `actions` at `index`.
#.........这里部分代码省略.........