码迷,mamicode.com
首页 > 其他好文 > 详细

pyqt最小化

时间:2014-12-14 22:37:22      阅读:251      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   ar   os   sp   for   on   

# -*- coding: cp936 -*-

 

 

#!/usr/bin/env python

 

# -*- coding:utf-8 -*-

 

from PyQt4 import QtCore, QtGui

 

class Window(QtGui.QMainWindow):

 

     def __init__(self):

 

         super(Window, self).__init__()

 

         self.setWindowTitle(u"托盘")

 

         icon = QtGui.QIcon("images/diamond.ico")

 

         self.setWindowIcon(icon)

 

         self.isTopLevel()

 

         self.trayIcon = QtGui.QSystemTrayIcon(self)

 

         self.trayIcon.setIcon(icon)

 

         self.trayIcon.show()

 

         self.trayIcon.activated.connect(self.trayClick) #点击托盘 

 

         self.trayIcon.setToolTip(u"托盘小程序") #托盘信息

 

         self.Menu() #右键菜单

 

     def Menu(self):

 

         self.minimizeAction = QtGui.QAction(u"最小化", self,triggered=self.hide)

 

         self.maximizeAction = QtGui.QAction(u"最大化",self,triggered=self.showMaximized)

 

         self.restoreAction = QtGui.QAction(u"还原", self,triggered=self.showNormal)

 

         self.quitAction = QtGui.QAction(u"退出", self,triggered=QtGui.qApp.quit)

 

         self.trayIconMenu = QtGui.QMenu(self)

 

         self.trayIconMenu.addAction(self.minimizeAction)

 

         self.trayIconMenu.addAction(self.maximizeAction)

 

         self.trayIconMenu.addAction(self.restoreAction)

 

         self.trayIconMenu.addSeparator() #间隔线

 

         self.trayIconMenu.addAction(self.quitAction)

 

         self.trayIcon.setContextMenu(self.trayIconMenu) #右击托盘 

 

     def closeEvent(self, event):

 

         if self.trayIcon.isVisible():

 

              self.hide()

 

              event.ignore()

 

     def trayClick(self,reason):

 

        if reason==QtGui.QSystemTrayIcon.DoubleClick: #双击

 

              self.showNormal()

 

        elif reason==QtGui.QSystemTrayIcon.MiddleClick: #中击

 

              self.showMessage()

 

        else:

 

              pass

 

     def showMessage(self):

 

        icon=QtGui.QSystemTrayIcon.Information

 

        self.trayIcon.showMessage(u"提示信息",u"点我干嘛?",icon)

 

if __name__ == ‘__main__‘:

 

    import sys

 

    app = QtGui.QApplication(sys.argv)

 

    frm = Window()

 

    frm.show()

 

    sys.exit(app.exec_())

 bubuko.com,布布扣

pyqt最小化

标签:style   blog   http   io   ar   os   sp   for   on   

原文地址:http://www.cnblogs.com/mhxy13867806343/p/4163137.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!