def createAttributePixmap(char, background=Qt.black, color=Qt.white): """ Create a QIcon with a given character. The icon is 13 pixels high and wide. :param char: The character that is printed in the icon :type char: str :param background: the background color (default: black) :type background: QColor :param color: the character color (default: white) :type color: QColor :rtype: QIcon """ icon = QtGui.QIcon() for size in (13, 16, 18, 20, 22, 24, 28, 32, 64): pixmap = QtGui.QPixmap(size, size) pixmap.fill(Qt.transparent) painter = QtGui.QPainter() painter.begin(pixmap) painter.setRenderHints(painter.Antialiasing | painter.TextAntialiasing | painter.SmoothPixmapTransform) painter.setPen(background) painter.setBrush(background) margin = 1 + size // 16 text_margin = size // 20 rect = QtCore.QRectF(margin, margin, size - 2 * margin, size - 2 * margin) painter.drawRoundedRect(rect, 30.0, 30.0, Qt.RelativeSize) painter.setPen(color) font = painter.font() # type: QtGui.QFont font.setPixelSize(size - 2 * margin - 2 * text_margin) painter.setFont(font) painter.drawText(rect, Qt.AlignCenter, char) painter.end() icon.addPixmap(pixmap) return icon
def _get_buffer(size, filename): return QtGui.QPixmap(int(size.width()), int(size.height()))
# -*- coding: utf-8 -*- SETTINGS_PRIORITY = 10 import os, AnyQt from pyforms import conf if conf.PYFORMS_MODE == 'GUI': from AnyQt import QtGui def path(filename): return os.path.join(os.path.dirname(__file__), 'icons', filename) PYFORMS_ICON_VIDEOPLAYER_PAUSE_PLAY = QtGui.QIcon() PYFORMS_ICON_VIDEOPLAYER_PAUSE_PLAY.addPixmap(QtGui.QPixmap(path('play.png')), mode=QtGui.QIcon.Normal, state=QtGui.QIcon.Off) PYFORMS_ICON_VIDEOPLAYER_PAUSE_PLAY.addPixmap(QtGui.QPixmap(path('pause.png')), mode=QtGui.QIcon.Normal, state=QtGui.QIcon.On) PYFORMS_ICON_CODEEDITOR_SAVE = QtGui.QIcon(path('export.png')) PYFORMS_PIXMAP_EVENTTIMELINE_ZOOM_IN = QtGui.QPixmap(path('zoom_in.png')) PYFORMS_PIXMAP_EVENTTIMELINE_ZOOM_OUT = QtGui.QPixmap(path('zoom_out.png')) PYFORMS_ICON_EVENTTIMELINE_IMPORT = QtGui.QIcon(path('import.png')) PYFORMS_ICON_EVENTTIMELINE_EXPORT = QtGui.QIcon(path('export.png')) PYFORMS_ICON_FILE_OPEN = QtGui.QIcon(path('link.png'))