PyQt5基础学习-掩膜实现不规则形状图片 1.QWidget.setMask(设置掩膜) 2.QPainter().drawPixmap(绘制图片)
设置掩膜,在画图时,导入掩膜的长和宽
AbnormityWindow.py
""" 实现不规则窗口(异形窗口) 通过mask实现异形窗口 需要一张透明的png图, 透明部分被扣出, 形成一个非矩形区域 """ import sys from PyQt5.QtWidgets import * from PyQt5.QtGui import * class AbnormityWindow(QWidget): def __init__(self): super(AbnormityWindow, self).__init__() self.setWindowTitle("异形窗口") self.pix = QBitmap("../picture/mask.png") self.resize(self.pix.size()) self.setMask(self.pix) def paintEvent(self, event): painter = QPainter(self) painter.drawPixmap(0, 0, self.pix.width(), self.pix.height() , QPixmap("../picture/screen1.jpg")) if __name__ == "__main__": app = QApplication(sys.argv) form = AbnormityWindow() form.show() sys.exit(app.exec_())
每天更新pyQt5内容