python实现360皮肤按钮控件示例

(编辑:jimmy 日期: 2024/11/21 浏览:2)

复制代码 代码如下:
#!/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, 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

 #更改皮肤背景
  #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_())

一句话新闻
高通与谷歌联手!首款骁龙PC优化Chrome浏览器发布
高通和谷歌日前宣布,推出首次面向搭载骁龙的Windows PC的优化版Chrome浏览器。
在对骁龙X Elite参考设计的初步测试中,全新的Chrome浏览器在Speedometer 2.1基准测试中实现了显著的性能提升。
预计在2024年年中之前,搭载骁龙X Elite计算平台的PC将面世。该浏览器的提前问世,有助于骁龙PC问世就获得满血表现。
谷歌高级副总裁Hiroshi Lockheimer表示,此次与高通的合作将有助于确保Chrome用户在当前ARM兼容的PC上获得最佳的浏览体验。