def modify(self, img: QtGui.QPixmap, mult: float=1.0, rounding: int=0, cut: int=5):
if img.width() == 0 or img.height() == 0:
log.info("FATAL ERROR: IMG NOT LOADED")
return img
img = QtGui.QPixmap(img)
h = img.height()
w = img.width()
color = QtGui.QColor(0, 0, 0, 0) # (r,g,b, density)
pix = QtGui.QPixmap(QtCore.QSize(w, h))
pix.fill(color)
if not rounding > 0:
cut = 0
rect = QtCore.QRectF(-1 + cut, -1 + cut, 2 + w - cut * 2, 2 + h - cut * 2)
painter = QtGui.QPainter()
painter.begin(pix)
painter.setRenderHints(QtGui.QPainter.Antialiasing, True)
path = QtGui.QPainterPath()
path.addRoundedRect(rect, rounding, rounding)
painter.drawPath(path)
brush = QtGui.QBrush()
brush.setTexture(img)
painter.fillPath(path, brush)
painter.end()
return pix.scaledToWidth(pix.width() * mult)
# credits to: http://python.6.x6.nabble.com/Rounded-corners-td4716825.html
评论列表
文章目录