Search code examples
c++qtqt4qgraphicsview

Handling MouseEvents in Qt c++


Sorry for my beginner's question... What is the easiest way to define procedures, which are executed when MousePressEvent or MouseReleaseEvent occurs?

For now I am defining my own class (MyGraphicsView class), which inherits QGraphicsView and I am reimplementing mouse events (which are virtual functions). It works fine but is there any way to solve this problem without a need to define a new class? Can I connect Events with Slots somehow?

Thanks for your help.


Solution

  • This thread on the Qt Centre forum describes quite well what your options are. Simply put:

    1. Do what you are doing (ie subclassing and reimplementing)

    2. Work with an event filter as described in the thread and link therein.