[英]clickable event on QLabel in python using pyqt4?
I am working in python GUI using pyqt4 library and new with signal and slots. 我正在python GUI中使用pyqt4库和新的信号和插槽。 I don't know how to put event on label name QPLabel
. 我不知道怎么把事件放在标签名QPLabel
。 Here is my code : 这是我的代码:
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName(_fromUtf8("Form"))
Form.resize(759, 598)
font = QtGui.QFont()
font.setPointSize(12)
...
...
...
self.QPLabel = QtGui.QLabel(Form)
self.QPLabel.setGeometry(QtCore.QRect(620, 420, 141, 20))
QtCore.QObject.connect(self.QPLabel, QtCore.SIGNAL(_fromUtf8("clicked()")), self.doSomething)
def doSomething(self):
print 'Label click'
Anybody what should I do for event on label for doing some action. 任何人我应该为标签上的事件做些什么来做一些动作。
Update the following line: 更新以下行:
QtCore.QObject.connect(self.QPLabel, QtCore.SIGNAL(_fromUtf8("clicked()")), self.doSomething)
To: 至:
self.QPLabel.mousePressEvent = self.doSomething
and add the event
parameter to doSomthing
并将event
参数添加到doSomthing
...
def doSomething(self, event):
...
QLabel
doesn't have a signal clicked
, so you can do one of the following: QLabel
没有clicked
信号,因此您可以执行以下操作之一:
A) Derive a custom class from QLabel
implementing handlers for mouse events. A)从QLabel
派生自定义类,实现鼠标事件的处理程序。
B) Implement the event handlers in Ui_Form
, using standard QLabels
and install the form as an event filter for the labels ( self.QPLabel.installEventFilter (self)
). B)使用标准QLabels
在Ui_Form
实现事件处理程序, Ui_Form
表单安装为标签的事件过滤器( self.QPLabel.installEventFilter (self)
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.