Handling MouseEvents in Qt c++

Marcin picture Marcin · Aug 10, 2010 · Viewed 10.2k times · Source

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.

Answer

rubenvb picture rubenvb · Aug 10, 2010

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.