[SOLVED] Stop Event Bubble on QFrame Click Custom Event Handler
-
I added an event filter for a QFrame with:
ui->myFrame->installEventFilter(this);
and
bool Inline::eventFilter(QObject *obj, QEvent *event) { qDebug() << obj << event; }
It's firing a mouseButtonPressed event even when on a subcontrol of the parent QFrame control. How do I stop the event bubble so that I only see debug output when clicking on the QFrame control itself, not any subcontrol?
-
@maximo said:
eventFilter
Hi, I think if you return true it means it has been handled.
Also, if you just want to be able to click on frame then overriding
protected: void MyFrame::mousePressEvent(QMouseEvent *qevent) { if (qevent->button() == Qt::LeftButton) { } };
might work better?
-
Hi,
Check that obj is myFrame and only print something in this case.
And you should also return the value of the base class implementation of eventFilter
-
@mrjj How do I override? What do I place in the header file? What do I place in the CPP file?
-
@maximo
Hi
You would create a new C++ Object via the new dialog. (like for the UI)
New ->
C++ ->
C++ Class
(Dialog shows)
Then
ClassName : MyFrame
Base Class (the dropdown) WidgetNow you have a new widget . and you would then
add the mousepress to the .H fileAnd can then use the promote trick to place it on the mainscreen or where you want it.
note when you place it in .h file, then dont put classname:: in from, so it would be
#include <QWidget> class MyFrame : public QWidget { Q_OBJECT public: explicit MyFrame(QWidget *parent = 0); protected: void mousePressEvent(QMouseEvent *qevent) { if (qevent->button() == Qt::LeftButton) { } } };