from PySide.QtCore import Qt, QCoreApplication class MyObject(QtCore.QObject): def __init__(self, parent=None): super(MyObject, self).__init__(parent) def event(self, event): if event.type() == Qt.MouseButtonPress: print("Mouse pressed") elif event.type() == Qt.MouseButtonRelease: print("Mouse released") return super(MyObject, self).event(event) app = QCoreApplication([]) obj = MyObject() app.exec_()
from PySide.QtCore import QObject, Signal, Slot class MyObject(QObject): my_signal = Signal() @Slot() def my_slot(self): print("Slot called") obj = MyObject() obj.my_signal.connect(obj.my_slot) obj.my_signal.emit()This code creates a new subclass of QObject and defines a new signal my_signal. It also defines a new slot my_slot that prints a message when called. The signal is connected to the slot using obj.my_signal.connect(obj.my_slot), and then the signal is emitted using obj.my_signal.emit(). This code demonstrates how to use signals and slots to communicate between different parts of a PySide QtCore application.