pyqt实现抗锯齿不规则窗口

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

直接上代码,safe.png为具备alpha通道的png图片输入图片说明

# coding:utf-8
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from PyQt4 import QtCore, QtGui


class MyForm(QWidget):

    def mousePressEvent(self, event):

        # 只能是鼠标左键移动和改变大小
        if(event.button() == Qt.LeftButton):
            self.mouse_press = True

        # 窗口移动距离
        self.move_point = event.globalPos() - self.pos()

    def mouseReleaseEvent(self, event):

        self.mouse_press = False

    def mouseMoveEvent(self, event):

        # 移动窗口
        if(self.mouse_press):
            self.move_pos = event.globalPos()
            self.move(self.move_pos - self.move_point)

    def __init__(self, parent=None):
        super(MyForm, self).__init__(parent)

        self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
        self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
        self.pix = QPixmap("safe.png")
        # self.resize(self.pix.size())
        self.setMask(self.pix.mask())

    def paintEvent(self, event):
        painter = QPainter(self)
        painter.drawPixmap(0, 0, self.pix.width(), self.pix.height(), self.pix)


app = QApplication([])
form = MyForm()
form.show()
app.exec_()

转载于:https://my.oschina.net/lastmagician/blog/809892

你可能感兴趣的:(pyqt实现抗锯齿不规则窗口)