本文整理汇总了Python中python_qt_binding.QtGui.QIcon.addPixmap方法的典型用法代码示例。如果您正苦于以下问题:Python QIcon.addPixmap方法的具体用法?Python QIcon.addPixmap怎么用?Python QIcon.addPixmap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类python_qt_binding.QtGui.QIcon
的用法示例。
在下文中一共展示了QIcon.addPixmap方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_icon
# 需要导入模块: from python_qt_binding.QtGui import QIcon [as 别名]
# 或者: from python_qt_binding.QtGui.QIcon import addPixmap [as 别名]
def make_icon(self, image_list, mode=QIcon.Normal, state=QIcon.On):
"""
Helper function to create QIcons from lists of image files
Warning: svg files interleaved with other files will not render correctly
:param image_list: list of image paths to layer into an icon.
:type image: list of str
:param mode: The mode of the QIcon to be created.
:type mode: int
:param state: the state of the QIcon to be created.
:type state: int
"""
if type(image_list) is not list:
image_list = [image_list]
if len(image_list) <= 0:
raise TypeError('The list of images is empty.')
num_svg = 0
for item in image_list:
if item[-4:].lower() == '.svg':
num_svg = num_svg + 1
if num_svg != len(image_list):
# Legacy support for non-svg images
icon_pixmap = QPixmap()
icon_pixmap.load(image_list[0])
painter = QPainter(icon_pixmap)
for item in image_list[1:]:
painter.drawPixmap(0, 0, QPixmap(item))
icon = QIcon()
icon.addPixmap(icon_pixmap, mode, state)
painter.end()
return icon
else:
# rendering SVG files into a QImage
renderer = QSvgRenderer(image_list[0])
icon_image = QImage(renderer.defaultSize(), QImage.Format_ARGB32)
icon_image.fill(0)
painter = QPainter(icon_image)
renderer.render(painter)
if len(image_list) > 1:
for item in image_list[1:]:
renderer.load(item)
renderer.render(painter)
painter.end()
# Convert QImage into a pixmap to create the icon
icon_pixmap = QPixmap()
icon_pixmap.convertFromImage(icon_image)
icon = QIcon(icon_pixmap)
return icon