I am working in python GUI using pyqt4 library and new with signal and slots. I don't know how to put event on label name 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.
PyQt4 is a comprehensive set of Python bindings for Digia's Qt cross platform GUI toolkit. PyQt4 supports Python v2 and v3.
A QLabel object acts as a placeholder to display non-editable text or image, or a movie of animated GIF. It can also be used as a mnemonic key for other widgets. Plain text, hyperlink or rich text can be displayed on the label.
PyQt is a Python binding for Qt, which is a set of C++ libraries and development tools that include platform-independent abstractions for Graphical User Interfaces (GUI), as well as networking, threads, regular expressions, SQL databases, SVG, OpenGL, XML, and many other powerful features.
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
... def doSomething(self, event): ...
QLabel
doesn't have a signal clicked
, so you can do one of the following:
A) Derive a custom class from QLabel
implementing handlers for mouse events.
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)
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With