PYQT Implementation window Border shadow effect (python) __python

Source: Internet
Author: User

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:


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.