PyQt5 利用paintEvent绘制窗口背景图片
#! /usr/bin/env python
# -*- coding:utf-8 -*-
from PyQt5.QtWidgets import QApplication, QWidget
from PyQt5.QtGui import QIcon, QPixmap, QPainter
import sys
class M_Win(QWidget):
def __init__(self):
super().__init__()
self.m_ui()
def m_ui(self):
self.resize(950, 200)
self.setWindowTitle("利用PaintEvent绘制窗口图片")
self.setWindowIcon(QIcon("./icon/title.png"))
def paintEvent(self, event):
painter = QPainter(self)
pixmap = QPixmap("./images/bg.gif")
painter.drawPixmap(self.rect(), pixmap)
if __name__ == "__main__":
app = QApplication(sys.argv)
win = M_Win()
win.show()
sys.exit(app.exec_())