# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'Q3.ui'
#
# Created: Fri Jun 01 15:47:36 2018
# by: PyQt4 UI code generator 4.11.3
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class MyLabel(QtGui.QLabel):
MyLabelPressedSignal=QtCore.pyqtSignal()
def __init__(self,parent=None):
super(MyLabel,self).__init__(parent)
self.MyLabelPressed=0
'''
def mouseDoubleClickEvent(self,e):
print 'mouse double clicked'
'''
def mousePressEvent(self,e):
#print 'mousePressEvent'
self.MyLabelPressed=1
def mouseReleaseEvent(self,e):
#print 'mouseReleaseEvent'
if self.MyLabelPressed==1:
self.MyLabelPressedSignal.emit()
self.MyLabelPressed=0
'''
def focusInEvent(self,e):
print 'focusInEvent'
def focusOutEvent(self,e):
print 'focusOutEvent'
def moveEvent(self,e):
print 'moveEvent'
def leaveEvent(self,e):#鼠标离开label
print 'leaveEvent'
def enterEvent(self,e):#鼠标移入label
print 'enterEvent'
def mouseMoveEvent(self,e):
print 'mouseMoveEvent'
'''
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName(_fromUtf8("Dialog"))
Dialog.resize(520, 402)
self.label = MyLabel(Dialog)
self.label.setGeometry(QtCore.QRect(130, 100, 241, 191))
self.label.setStyleSheet(_fromUtf8("background-color: rgb(170, 85, 255);"))
self.label.setObjectName(_fromUtf8("label"))
self.retranslateUi(Dialog)
#self.label.MyLabelPressedSignal.connect(self.doST2)
QtCore.QObject.connect(self.label, QtCore.SIGNAL(_fromUtf8("MyLabelPressedSignal()")), self.doST2)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
Dialog.setWindowTitle(_translate("Dialog", "Dialog", None))
self.label.setText(_translate("Dialog", "TextLabel", None))
def doST2(self):
print 'doST2'
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
Dialog = QtGui.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.show()
sys.exit(app.exec_())
pyqt4 QLabel添加click信号
最新推荐文章于 2024-07-04 22:31:36 发布