Python implements the 360 Skin button Control Sample _python

Source: Internet
Author: User

Copy Code code 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 () #显示皮肤
Self.skin_name_label = Qlabel () #显示皮肤名称
Self.download_count_label = Qlabel () #显示下载次数
Self.use_skin_button = Qpushbutton () #使用此皮肤按钮
Self.setcursor (Qt.pointinghandcursor)

Self.use_skin_button.setStyleSheet ("border-radius:3px border:1px solid RGB (180, 190,) 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

#更改皮肤背景
#self. Pixmap ()
Self.skin_label.setPixmap (Qpixmap (self.background_name))

#更改皮肤名称
Self.skin_name_label.setText (Skin_name)

#更改下载次数
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):
#绘制边框
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):
#只能是鼠标左键移动和改变大小
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.exec_ ())

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.