Adding QMouseEvent to QFrame created using Designer



  • Hello,

    I have been searching for a couple of days for an answer to this:

    I have created a simple window with a QFrame in it using Designer. The QFrame just has 4 QLabels in it. I am trying to figure out how to detect mouse clicks inside the QFrame. The name of the QFrame is frame01.
    I tried creating a class (frame01.cpp and frame01.h) and overriding the mousePressEvent and mouseReleaseEvent methods, but no luck.

    I am wondering if there is an example out there that I have missed. Are things more complicated because I created the window with Designer? I also tried looking to see if I could set it up in Designer, but I could not find any place to set it up.

    Any help would really be appreciated.

    Thanks

    Aldo L.



  • You have two ways to do this.

    1. Reimplement QFrame. But if you want use it with QtDesigner this is not for you.
    2. Install event filter. "Take a look":http://qt-project.org/doc/qt-5/qobject.html#installEventFilter .


  • For anyone interested, using the eventFilter worked. It just took me some time to figure out how to correctly create the class that implements the eventFilter(QObject, QEvent) method.

    Thanks qxoz


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.