赞
踩
#coding=utf-8 import sys from PySide import QtGui from PySide import QtCore class Tuopan(QtGui.QLabel): def __init__(self): super(Tuopan, self).__init__() self.setWindowTitle("Tray!") self.setWindowFlags(QtCore.Qt.SplashScreen) #self.setWindowOpacity(0) self.pic=QtGui.QPixmap('kato.png') self.pic.scaled(580,580) self.setPixmap(self.pic) self.setScaledContents(True) self.setMask(self.pic.mask()) self.setAlignment(QtCore.Qt.AlignCenter) self.dragPosition=None #self.resize(400,400) #self.setMaximumWidth(400) #self.setMaximumHeight(100) self.show() self.createContextMenu() def createContextMenu(self): # 必须将ContextMenuPolicy设置为Qt.CustomContextMenu # 否则无法使用customContextMenuRequested信号 self.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self.customContextMenuRequested.connect(self.showContextMenu) # 创建QMenu self.contextMenu = QtGui.QMenu(self) self.actionA = self.contextMenu.addAction(u'执行exe') print self.actionA self.actionB = self.contextMenu.addAction(u'关机') self.actionC = self.contextMenu.addAction(u'关闭') # 将动作与处理函数相关联 # 这里为了简单,将所有action与同一个处理函数相关联, # 当然也可以将他们分别与不同函数关联,实现不同的功能 self.actionA.triggered.connect(self.action_add) self.actionB.triggered.connect(self.action_del) self.actionC.triggered.connect(self.action_close) def showContextMenu(self, pos): self.contextMenu.move(self.pos() + pos) self.contextMenu.show() def action_add(self): pass def action_del(self): pass def action_close(self): self.close() def wheelEvent(self, event): max = 500 min = 100 '''print 'window',self.width() print 'window',self.height() print 'pic',self.pic.width() print 'pic',self.pic.height()''' value=event.delta() if value: if (self.width()+value*0.1)>=100 and (self.width()+value*0.1)<=500: print self.width() self.resize(self.width()+value*0.1,self.width()+value*0.01) pix=self.pic.scaled(self.pic.width()+value*0.1,self.pic.width()+value*0.01) self.setPixmap(pix) self.setMask(self.pic.mask()) self.repaint() self.update() #self.pic.scaledToHeight(self.width()+value*0.1) '''if event.delta() >= 500: #滚动3% new = self.pic.width()+ max*0.03 if new > max: new = max self.resize(new,new) self.pic.scaledToWidth(new) self.pic.scaledToHeight(new) elif event.delta() <= 100: new = self.pic.width()- max*0.03 if new < min: new = min self.resize(new,new) self.pic.scaledToWidth(new) self.pic.scaledToHeight(new) else: print 11111111111111111''' def mousePressEvent(self,event): if event.button()==QtCore.Qt.LeftButton: self.dragPosition=event.globalPos()-self.frameGeometry().topLeft() event.accept() if event.button()==QtCore.Qt.RightButton: pass #self.close() if event.button()==QtCore.Qt.MiddleButton: pass def mouseMoveEvent(self,event): if event.buttons()& QtCore.Qt.LeftButton: self.move(event.globalPos()-self.dragPosition) event.accept() if __name__ == '__main__': app = QtGui.QApplication(sys.argv) trans = Tuopan() trans.show() sys.exit(app.exec_())
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。