pyqt4 label 클릭 이벤트, label 스티커

4125 단어 Pyqt
#-*- coding:utf-8 -*-
#pyqt4 label  label , 
####label , , , 
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys
###########tooltip  
try:
    _encoding = QApplication.UnicodeUTF8
    def _translate(context, text, disambig):
        return QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
    def _translate(context, text, disambig):
        return QApplication.translate(context, text, disambig)

class myLabel(QLabel):
    def __init__(self,parent = None):
        super(myLabel,self).__init__(parent)

    def mousePressEvent(self, e):## 
        print "you clicked the label"

    def mouseReleaseEvent(self, QMouseEvent):
        print 'you have release the mouse'

class MyWindow(QDialog,QWidget):
    def __init__(self,parent = None):
        super(MyWindow,self).__init__(parent)
        self.resize(400,400)
        self.mainlayout = QGridLayout(self)
        self.myLabelEx = myLabel()
        #self.myLabelEx.setText(u" ")
        self.mainlayout.addWidget(self.myLabelEx)
        self.myLabelEx.setPixmap(QPixmap("help.png"))##### 
        self.myLabelEx.setToolTip(_translate("MainWindow", u" ~", None))



app=QApplication(sys.argv)
window=MyWindow()
window.show()
app.exec_()

좋은 웹페이지 즐겨찾기