A description of Qt events, and QListWidget example of handling mouse events.PyQt implements not only signal and slots for handling actions. There are also events that occur for example when we press a mouse button, a key, move the cursor, or timer runs out of time. For example QListWidget has a signal "itemClicked", which is send when an item is clicked - by any mouse button. If we want more controll over mose clicks we can use events like:
To use an event we have to make our own class that inherits the widget we want to use. Our class must have methods named as events that we want to use (like those two examples). Event object will be under the method argument. Here is an working example: We made our own class that inherits QListWidget, and we defined two methods for two events. QMouseEvent hidden under event argument contains such methods as "x()" and "y()" which contain the place location on the widget where the click/release occurred. The button() method will inform us which button was used. Also we use some QListWidget methods like very nice one: itemAt(X, Y), which will return the item if any under X, Y coordinates. We select the item we click on. Just save the code in a file and run it from a terminal - and when you click on an item - event messages will be printed there.
mouseReleaseEvent (self, QMouseEvent e) mousePressEvent (self, QMouseEvent e)