Find signals and slots from any QT widget object.

# -*- coding: utf-8 -*-
##  Copyright 2019 Trevor van Hoof and Jan Pijpers.
##  Licensed under the Apache License, Version 2.0
##  Downloaded from or
##  See the license file attached or on

Name: findSignalsAndSlotsQt

This script gives you all available signals and slots on a qt widget object.
Normally you can just check the documentation, however if custom signals and slots are used its hard to find them.
We do this by using the meta class from the object.

I used this to find the timechanged event on the maya timeControl widget.

import sys
from PySide.QtGui import * ## pip install PySide
from PySide import QtCore
def get_widget(name):
        Kind of slow method of finding a widget by object name.
    :param name:
    for widget in QApplication.allWidgets():
            if name in widget.objectName():
                return widget
        except Exception as e:
            print e
    return None 

def test( *arg, **kwarg):
        Simple test function to see what the signal sends out.
    :param arg:
    :param kwarg:

    print "The args are: ", arg
    print "The kwargs are: ", kwarg

if __name__ == "__main__":

    ## Here we make a simple QLineEdit for argument sake ...
    app = QApplication(sys.argv)
    wid = QLineEdit()

    ## Find the widget by name.
    ## See the qt ui list hierarchy script to find all widgets in a qt ui.
    widgetObjectName = "myLineEdit"
    widgetObject = get_widget(widgetObjectName)
    if not widgetObject:
        raise Exception("Could not find widget: %s" %widgetObjectName)

    ## Sanity check
    if not wid == widgetObject:
        raise Exception("Should not happen.XD")

    ## Get the meta data from this object
    meta = widgetObject.metaObject()

    ## Itterate over the number of methods available
    for methodNr in xrange(meta.methodCount()):
        method = meta.method(methodNr)
        ## If the method is a signal type
        if method.methodType() == QtCore.QMetaMethod.MethodType.Signal:
            ## Print the info.
            print "This is the signal name", method.signature()
            print "These are the signal arguments: ", method.parameterNames()
            ## If the method is a signal type
        if method.methodType() == QtCore.QMetaMethod.MethodType.Slot:
            ## Print the info.
            print "This is the slot name", method.signature()
            print "These are the slot arguments: ", method.parameterNames()

    output example:
    This is the signal name textChanged(QString)
    These are the signal arguments:  [PySide.QtCore.QByteArray('')]
    This is the signal name textEdited(QString)
    These are the signal arguments:  [PySide.QtCore.QByteArray('')]
    so now you can do
    any every time the text changes the 'test' function will be called 


Leave a Reply

Your email address will not be published. Required fields are marked *