[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?


  • Qt Champions 2016

    @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?


  • Lifetime Qt Champion

    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?


  • Qt Champions 2016

    @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) Widget

    Now you have a new widget . and you would then
    add the mousepress to the .H file

    And 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)
            {
           
            }
        }
    };
    

Log in to reply
 

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