本文整理匯總了Python中qtpy.QtGui.QPixmap.isNull方法的典型用法代碼示例。如果您正苦於以下問題:Python QPixmap.isNull方法的具體用法?Python QPixmap.isNull怎麽用?Python QPixmap.isNull使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類qtpy.QtGui.QPixmap
的用法示例。
在下文中一共展示了QPixmap.isNull方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: imageFiles
# 需要導入模塊: from qtpy.QtGui import QPixmap [as 別名]
# 或者: from qtpy.QtGui.QPixmap import isNull [as 別名]
def imageFiles(self, new_files):
"""
JSON-formatted dictionary keyed on states (integers), with filenames
of the image file to display for the state.
Parameters
----------
new_files : str
"""
self._state_images_string = str(new_files)
try:
new_file_dict = json.loads(self._state_images_string)
except Exception:
self._state_images = {}
return
self._sizeHint = QSize(0, 0)
for (state, filename) in new_file_dict.items():
if is_pydm_app():
try:
file_path = self.app.get_path(filename)
except Exception as e:
logger.exception("Couldn't get file with path %s", filename)
file_path = filename
else:
file_path = filename
# First, lets try SVG. We have to try SVG first, otherwise
# QPixmap will happily load the SVG and turn it into a raster image.
# Really annoying: We have to try to load the file as SVG,
# and we expect it will fail often (because many images aren't SVG).
# Qt prints a warning message to stdout any time SVG loading fails.
# So we have to temporarily silence Qt warning messages here.
qInstallMessageHandler(self.qt_message_handler)
svg = QSvgRenderer()
svg.repaintNeeded.connect(self.update)
if svg.load(file_path):
self._state_images[int(state)] = (filename, svg)
self._sizeHint = self._sizeHint.expandedTo(svg.defaultSize())
qInstallMessageHandler(None)
continue
qInstallMessageHandler(None)
# SVG didn't work, lets try QPixmap
image = QPixmap(file_path)
if not image.isNull():
self._state_images[int(state)] = (filename, image)
self._sizeHint = self._sizeHint.expandedTo(image.size())
continue
# If we get this far, the file specified could not be loaded at all.
logger.error("Could not load image: {}".format(filename))
self._state_images[int(state)] = (filename, None)