Refer to the QT example and make a record:
Ideas:
1. Prepare the picture
2. Set Border display width
Self. Shadow_width=8
3. Implementation methods
def DrawShadow (self,painter): #绘制左上角, lower left corner, upper right corner, lower right corner, top, bottom, left, right Border self.pixmaps=qstringlist () self.pixmaps
. Append (QString ("./img/border/left_top.png")) Self.pixmaps.append (QString ("./img/border/left_bottom.png")) Self.pixmaps.append (QString ("./img/border/right_top.png")) Self.pixmaps.append (QString ("./img/border/right_ Bottom.png ")) Self.pixmaps.append (QString ("./img/border/top_mid.png ")) Self.pixmaps.append (QString ("./img/ Border/bottom_mid.png ")) Self.pixmaps.append (QString ("./img/border/left_mid.png ")) Self.pixmaps.append (QSt Ring ("./img/border/right_mid.png")) painter.drawpixmap (0, 0, self. Shadow_width, self. Shadow_width, Qpixmap (Self.pixmaps[0])) #左上角 Painter.drawpixmap (Self.width ()-self. Shadow_width, 0, self. Shadow_width, self. Shadow_width, Qpixmap (self.pixmaps[2])) #右上角 Painter.drawpixmap (0,self.height ()-self. Shadow_width, self. Shadow_width, self. Shadow_width, Qpixmap (self.pixmaps[1)) #左下角 Painter.drawpixmap (Self.width ()-self). Shadow_width, Self.height ()-self. Shadow_width, self. Shadow_width, self. Shadow_width, Qpixmap (self.pixmaps[3]) #右下角 painter.drawpixmap (0, self. Shadow_width, self. Shadow_width, Self.height () -2*self. Shadow_width, Qpixmap (Self.pixmaps[6]). Scaled (self. Shadow_width, Self.height () -2*self. shadow_width)) #左 Painter.drawpixmap (Self.width ()-self. Shadow_width, self. Shadow_width, self. Shadow_width, Self.height () -2*self. Shadow_width, Qpixmap (Self.pixmaps[7]). Scaled (self. Shadow_width, Self.height ()-2*self. shadow_width)) #右 painter.drawpixmap (self. Shadow_width, 0, Self.width () -2*self. Shadow_width, self. Shadow_width, Qpixmap (Self.pixmaps[4]). Scaled (Self.width () -2*self. Shadow_width, self. shadow_width)) #上 painter.drawpixmap (self. Shadow_width, Self.height ()-self. Shadow_width, Self.width () -2*self. Shadow_width, self. Shadow_width, Qpixmap (Self.pixmaps[5]). Scaled (Self.width () -2*self. Shadow_width, self. Shadow_width)) #Under
4. Drawing
def paintevent (self, event):
painter = Qpainter (self)
self.drawshadow (painter)
Painter.setpen (qt.nopen )
Painter.setbrush (qt.white)
painter.drawrect (Qrect (self. Shadow_width, self. Shadow_width, Self.width () -2*self. Shadow_width, Self.height () -2*self. Shadow_width))
Write a class, as long as you inherit this class on it, remember to remove the title bar and set the background transparent:
Self.setwindowflags (Qt.framelesswindowhint)
Self.setattribute (Qt.wa_translucentbackground)
The effect is as follows: