Copy codeThe Code is as follows:
#! /Usr/bin/python
#-*-Coding: UTF-8 -*-
From PyQt4.QtGui import *
From PyQt4.QtCore import *
From PyQt4.Qt import *
Class ChangeSkinWidget (QWidget ):
Def _ init _ (self, parent = None ):
Super (ChangeSkinWidget, self). _ init _ (parent)
Self. setFixedSize (140,160)
Self. mouse_press = False
Self. mouse_enter = False
# Self. pixmap = QPixmap ()
Self. pixmap_name = ""
Self. skin_label = QLabel () # display skin
Self. skin_name_label = QLabel () # display skin name
Self. download_count_label = QLabel () # display the number of downloads
Self. use_skin_button = QPushButton () # use this skin button
Self. setCursor (Qt. PointingHandCursor)
Self. use_skin_button.setStyleSheet ("border-radius: 3px border: 1px solid rgb (180,190,200) color: rgb (70, 70, 70) background: transparent ")
Self. skin_label.setScaledContents (True)
Self. skin_label.setFixedSize (100, 65)
Self. use_skin_button.setFixedSize (85, 25)
Self. background_layout = QVBoxLayout ()
Self. background_layout.addWidget (self. skin_label, 0, Qt. AlignCenter)
Self. background_layout.addWidget (self. skin_name_label, 0, Qt. AlignCenter)
Self. background_layout.addWidget (self. download_count_label, 0, Qt. AlignCenter)
Self. background_layout.addWidget (self. use_skin_button, 0, Qt. AlignCenter)
Self. background_layout.setSpacing (5)
Self. background_layout.setContentsMargins (0, 10, 0, 10)
Self. setLayout (self. background_layout)
Self. skin. connect (self. changeSkin)
Self. translateLanguage ()
Skin = pyqtSignal ()
Def changeSkin (self, pixmap_name, skin_name, download_count ):
Self. background_name = pixmap_name + "_big.png"
Self. pixmap_name = self. background_name
# Modifying skin background
# Self. pixmap ()
Self. skin_label.setPixmap (QPixmap (self. background_name ))
# Change skin name
Self. skin_name_label.setText (skin_name)
# Change the number of downloads
Self. download_count_label.setText (u "download count:" + download_count)
Def translateLanguage (self ):
Self. use_skin_button.setText (u "use skin ")
Def paintEvent (self, event ):
If (self. mouse_enter ):
# Draw borders
Painter = QPainter (self)
Pen = QPen (QColor (210,225,230 ))
Painter. setPen (pen)
Painter. drawRoundRect (0, 0, self. width ()-1, self. height ()-1, 5, 5)
Def mousePressEvent (self, event ):
# Only move the left mouse button and change the size
If (event. button () = Qt. LeftButton ):
Self. mouse_press = True
Self. emit (SIGNAL ("skin"), self. pixmap_name)
Def mouseReleaseEvent (self, event ):
Self. mouse_press = False
Def enterEvent (self, event ):
Self. mouse_enter = True
Self. update ()
Def leaveEvent (self, event ):
Self. mouse_enter = False
Self. update ()
If _ name _ = '_ main __':
Import sys
App = QApplication (sys. argv)
Skin = ChangeSkinWidget ()
Skin. show ()
Sys.exit(app.exe c _())