Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Stop Event Bubble on QFrame Click Custom Event Handler
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Stop Event Bubble on QFrame Click Custom Event Handler

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 1.9k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    maximo
    wrote on last edited by maximo
    #1

    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?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

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

      M 1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        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

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • mrjjM mrjj

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

          M Offline
          M Offline
          maximo
          wrote on last edited by
          #4

          @mrjj How do I override? What do I place in the header file? What do I place in the CPP file?

          mrjjM 1 Reply Last reply
          0
          • M maximo

            @mrjj How do I override? What do I place in the header file? What do I place in the CPP file?

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by mrjj
            #5

            @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)
                    {
                   
                    }
                }
            };
            
            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved