PyQt5 focusIN/Out events
Question: I am using Python 3.4 and Qt 5 for the first time. It's easy and I can
understand most of functionality which I need. But (there is always "but") I
don't understand how to use `focusOut`/`clearFocus`/`focusIn` events.

Am I right that old way:

    
    
    QObject.connect(self.someWidget, QtCore.SIGNAL('focusOutEvent()'), self.myProcedure)
    

...does not work in Qt5?

I tried to understand
[this](http://pyqt.sourceforge.net/Docs/PyQt5/signals_slots.html)
unsuccessfully. I'll be very thankful for a short example how to catch an
event when e.g some of many `QLineEdit` has lost focus.


Answer: The issue here is that `focusInEvent`/`clearFocus`/`focusOutEvent` are _not_
signals, they are _event handlers_. See for example [here](http://qt-
project.org/doc/qt-4.8/qwidget.html#focusInEvent). If you want to catch these
events you will need to re-implement the event handler on your object, for
example by subclassing QLineEdit.

    
    
    class MyQLineEdit(QLineEdit):
    
        def focusInEvent(self, e):
            # Do something with the event here
            super(MyQLineEdit, self).focusInEvent(e) # Do the default action on the parent class QLineEdit
    

In PyQt5 the syntax for signals themselves is considerably simpler. Taking for
example the `textEdited` signal from QLineEdit, you can use that as follows:

    
    
    self.someWidget.textEdited.connect( self.myProcedure )
    

This will connect your `self.myProcedure` function to the `textEdited` signal.
The target function will need to accept the event outputs, for example:

    
    
    void    textEdited ( const QString & text )
    

So you could define your `self.myProcedure` in your class as follows and it
will receive the `QString` sent by that event:

    
    
    def myProcedure(self, t):
        # Do something with the QString (text) object here
    

You can also define custom events as follows:

    
    
    from PyQt5.QtCore import QObject, pyqtSignal
    
    class Foo(QObject):
        an_event = pyqtSignal()
        a_number = pyqtSignal(int)
    

In each of these cases `pyqtSignal` is used to define a property of the `Foo`
class which you can connect to like any other signal. So for example to handle
the above we could create:

    
    
    def an_event_handler(self):
        # We receive nothing here
    
    def a_number_handler(self, i):
        # We receive the int
    

You could then `connect()` and `emit()` the events as follows:

    
    
    self.an_event.connect( self.an_event_handler )
    self.a_number.connect( self.a_number_handler )
    
    self.an_event.emit()   # Send the event and nothing else.
    self.a_number.emit(1)  # Send the event an an int.
    

The link you posted gives [more information on custom
events](http://pyqt.sourceforge.net/Docs/PyQt5/signals_slots.html), signal
naming and overloading with the new syntax.

