If you're using PyQT5 instead of Qt5, you can use Python's introspection abilities to find all signals of any class and connect them to a dummy slot (of a dummy object).
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from typing import Iterable
from PyQt5.QtCore import pyqtBoundSignal
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtCore import QObject
def list_all_signals(obj: QObject) -> Iterable[pyqtBoundSignal]:
attr_names = dir(obj)
attributes = (getattr(obj, attr_name) for attr_name in attr_names)
connectable = filter(lambda l: hasattr(l, "connect"), attributes)
return connectable
class SignalListener(QObject):
@pyqtSlot()
def universal_slot(self, *args, **kwargs):
print("Signal caught" + 30 * "-")
print("sender:", self.sender())
meta_method = (
self.sender().metaObject().method(self.senderSignalIndex())
)
print("signal:", meta_method.name())
print("signal signature:", meta_method.methodSignature())
SIGNAL_LISTENER = SignalListener()
def spy_on_all_signals(
obj: QObject, listener: SignalListener = SIGNAL_LISTENER
):
for signal in list_all_signals(obj):
signal.connect(SIGNAL_LISTENER.universal_slot)
The dummy slot now prints info about all signals emitted by an object.
For example, if you spy on a random QLineEdit like this:
some_line_edit = QLineEdit(self)
spy_on all_signals(some_line_edit)
A possible log of entering and exiting the line edit might look like this:
Signal caught ------------------------------
sender: <PyQt5.QtWidgets.QLineEdit object at 0x7f220f7a3370>
signal: b'cursorPositionChanged'
signal signature: b'cursorPositionChanged(int,int)'
Signal caught ------------------------------
sender: <PyQt5.QtWidgets.QLineEdit object at 0x7f220f7a3370>
signal: b'selectionChanged'
signal signature: b'selectionChanged()'
Signal caught ------------------------------
sender: <PyQt5.QtWidgets.QLineEdit object at 0x7f220f7a3370>
signal: b'selectionChanged'
signal signature: b'selectionChanged()'
Signal caught ------------------------------
sender: <PyQt5.QtWidgets.QLineEdit object at 0x7f220f7a3370>
signal: b'editingFinished'
signal signature: b'editingFinished()'