Mouse Events on QLabel Widget

Mouse Events on QLabel Widget

This is a problem when I want to detect Mouse Events on QLabel Widget. By default, we can not use QLabel to detect Mouse Events on QLabel Widget. If we want to add this feature, we must create a custum QLabel by self. With this tutorial, you can extend to create other QWidget by yourself.

We can detect Mouse Events on QLabel Widget with method mousePressEvent ( QMouseEventev ). For example, I create a class with name labelClick, implement mousePressEvent method with this code :


We can use this labelClick class in other class and if want to detect Mouse Events on QLabel Widget, we can that signal with this command :

This is a sample image when start running Mouse Events on QLabel Widget from above code :

Start Mouse Events on QLabel Widget
Running Mouse Events on QLabel Widget

And this is a sample output when we click with mouse button over our modification QLabel above :

Mouse Events on QLabel Widget
Mouse Events on QLabel Widget

This is a simple  tutorial how to detect Mouse Events on QLabel Widget. You can extend this tutorial to get mouseEvents on other Widget. If you have other method how to detect Mouse Events on QLabel Widget, please share 🙂

You can download the complete Mouse Events on QLabel Widget source code at here.

2 thoughts on “Mouse Events on QLabel Widget

Leave a Reply to serchmaa Cancel reply

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

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.