我正在尝试在QPixmap
. 我愚蠢地认为缩小它会做到这一点,但事实并非如此,正如你在这里看到的:
我已经尝试了很多东西,,,,QGraphicsPixmapItem()
但QGraphicsDropShadowEffect()
我想我错过了一些东西。我需要创建一个投影效果或其他东西,然后QPixmap
以某种方式将其重新绘制在 下。还是向外只填充几个像素?
这是我一直在使用的一些代码:
icon = "iconpath/icon.png"
base_pixmap = QtGui.QPixmap(icon)
color = QtGui.QColor("green")
# set black outline
mask = base_pixmap.createMaskFromColor(QtCore.Qt.transparent, QtCore.Qt.MaskInColor)
base_pixmap.fill(QtGui.QColor("black"))
# set mask
base_pixmap.setMask(mask)
# Take icon, edit size, add to pixmap
pixmap_image = QtGui.QPixmap(icon)
mask = pixmap_image.createMaskFromColor(QtCore.Qt.transparent, QtCore.Qt.MaskInColor)
pixmap_image.fill(color)
# set mask
pixmap_image.setMask(mask)
painter = QtGui.QPainter(self)
margin = 10 # shrink image to fit inside border
height_percent = (float(base_pixmap.height()) / 100) * float(margin)
width_percent = (float(base_pixmap.width()) / 100) * float(margin)
painter.drawPixmap(QtCore.QRect(width_percent / 2, height_percent / 2,
self.width() - width_percent,
self.height() - height_percent),
pixmap_image)
painter.end()