from PyQt5.QtGui import QImage, QPainter, QPixmap, QCompositionMode # create a new image image = QImage(400, 400, QImage.Format_RGBA8888) image.fill(QColor(255, 255, 255, 0)) # load an existing image existing_image = QPixmap('image.jpg') # draw the existing image with transparency painter = QPainter(image) painter.setCompositionMode(QCompositionMode_SourceOver) painter.drawImage(0, 0, existing_image.toImage()) painter.end()
from PyQt5.QtGui import QGradient, QPainter, QLinearGradient, QColor, QCompositionMode # create a new gradient gradient = QLinearGradient(0, 0, 400, 400) gradient.setColorAt(0, QColor(255, 0, 0)) gradient.setColorAt(1, QColor(0, 0, 255)) # draw the gradient with a blend mode painter = QPainter(widget) painter.setCompositionMode(QCompositionMode_SourceOver) painter.fillRect(0, 0, 400, 400, gradient) painter.end()Package library: PyQt5