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. Some questions about accept() and ignore() of event
Forum Updated to NodeBB v4.3 + New Features

Some questions about accept() and ignore() of event

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 9.0k Views 1 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.
  • B Offline
    B Offline
    bear234
    wrote on last edited by
    #1

    for example, we overwrite the fonction void mousePressEvent(QMouseEvent *event) for a class.

    if we write: event->accept()
    it means that this event is handled here, do not pass it to others.
    if we write: event->ignore()
    it means that we do nothing here, try to pass this event to other handlers.

    if I am right, plz tell me:
    who are other handlers? the base class?

    if it is the base class, well,
    if(WeDoNothing)
    {event->ignore();}
    and
    if(WeDoNothing)
    {BaseClass:mousePressEvent(event);}

    are they the same?

    can I write like this:
    event->accept();
    BaseClass::mousePressEvent(event);

    u see, i m confused by accept() ignore() and BaseClass::mousePressEvent(event)

    plz help me.

    thx in advance.

    1 Reply Last reply
    1
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Basically accept, ignore and calling base implementation are mutually exclusive and you should not mix them.

      accept() - indicates that you want this event and you will handle it your way

      ignore() - indicates that you don't want this event, the event will be propagated to the parent and handled there

      calling base - leave the handling to the default implementation of the base. It might call accept. It might call ignore. It might do additional stuff depending on what kind of event and class are they.

      As for default mouse events - it depends. The "container" widgets like frame will call ignore. Some others, like lineedits etc. will grab focus.
      You can also set a "Qt::WA_NoMousePropagation":http://qt-project.org/doc/qt-5/qt.html#WidgetAttribute-enum attribute on any widget to prevent it from handling their mouse events to the parent.

      1 Reply Last reply
      1
      • B Offline
        B Offline
        bear234
        wrote on last edited by
        #3

        thx.
        but for the ignore() and calling base, i m still confused.

        as u said, ignore() – indicates that you don’t want this event, the event will be propagated to the parent and handled there.

        so event->ignore() and BaseClass::fonction(event) are the same?

        [quote author="Chris Kawa" date="1389122103"]Basically accept, ignore and calling base implementation are mutually exclusive and you should not mix them.

        accept() - indicates that you want this event and you will handle it your way

        ignore() - indicates that you don't want this event, the event will be propagated to the parent and handled there

        calling base - leave the handling to the default implementation of the base. It might call accept. It might call ignore. It might do additional stuff depending on what kind of event and class are they.

        As for default mouse events - it depends. The "container" widgets like frame will call ignore. Some others, like lineedits etc. will grab focus.
        You can also set a "Qt::WA_NoMousePropagation":http://qt-project.org/doc/qt-5/qt.html#WidgetAttribute-enum attribute on any widget to prevent it from handling their mouse events to the parent.
        [/quote]

        1 Reply Last reply
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          No, base implementation doesn't necessary call ignore.
          Think about it like this:

          ignore() - I don't care about this event and I consciously decide to pass it to the parent.

          base - I might care about this event but I let base implementation decide if it should be kept by my class(via accept) or delegated to the parent(via ignore). It may also do other stuff that I don't want to know about.

          Base implementation is not the same as ignore, It may call ignore. It may call accept just as well. It may do any of those and then some more. It depends on a class and event.
          For example for dragging some additional state is set. Most basic mouse events are just ignored and passed to parent, but that's not a rule for all events and classes.

          1 Reply Last reply
          1
          • Chris KawaC Offline
            Chris KawaC Offline
            Chris Kawa
            Lifetime Qt Champion
            wrote on last edited by
            #5

            In terms of use cases:

            • I totally don't care about this event: call ignore()
            • I want only my own handling of this event: call accept() and do your stuff
            • I want to keep default behavior but add something to it: call base and then do your stuff, don't call accept() or ignore()
            • I want only the default behavior: only call base or don't overload at all
            1 Reply Last reply
            1
            • B Offline
              B Offline
              bear234
              wrote on last edited by
              #6

              OK i understand now

              thx a lot

              [quote author="Chris Kawa" date="1389127867"]In terms of use cases:

              • I totally don't care about this event: call ignore()
              • I want only my own handling of this event: call accept() and do your stuff
              • I want to keep default behavior but add something to it: call base and then do your stuff, don't call accept() or ignore()
              • I want only the default behavior: only call base or don't overload at all[/quote]
              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