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. installEventFilter a bit differently

installEventFilter a bit differently

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 402 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
    brkonator
    wrote on last edited by brkonator
    #1

    Hi, I was wondering how to process multiple events of one QObject without a need to subclass it and override some method. I know, there are generally 5 ways how to process events (described here), but in each one, I need to subclass either an object whose messages I want to process, or the object who is going to filter the events before they get to the receiver (eventFilter). Why is there no method like QObject::installEventFilter which takes a functor/function pointer (taking a pointer to a QEvent and returning bool)? Are there any problems that would arise from this type of event-handling? Thanks in advance.

    EDIT:
    I even add the code, so that there's no confusion

    // this would be added into the QObject class
    class QObject
    {
    public:
        void installEventFilter(std::function<bool(QEvent*)> functor);
    };
    
    // -------------------------------
    // USER'S CODE
    // this can be some global or static member function - doesn't really matter
    bool MyEventFilteringFunction(QEvent* ev)
    {
        if (ev->type() == QEvent::Paint)
        {
            // do something
            return true;
        }
    
        return false;
    }
    
    // somewhere in the code
    // no need to subclass and override button, nor it's parent dialog or anything
    QPushButton b;
    b.installEventFilter(&MyEventFilteringFunction);
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Why:

      • usually because nobody requested nor provided that feature
      • not feasible for technical reasons at that time
      • not possible to integrate it for some reasons

      All in all, you can open a feature request for that to get the discutions started. Even better if you can submit a patch that implements what you are asking for.

      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
      2
      • B Offline
        B Offline
        brkonator
        wrote on last edited by
        #3

        Thanks for your answer. All I'm asking is - would this be a sane thing to implement, or am I missing something obvious? If the rest of the event-system allowed such functionality, would it be able to e.g. replace the original installEventFilter method? Obviously, my version would need to have 1 additional parameter besides QEvent - that would be QObject representing the receiver of the event. I don't have any specific requirement, this is just an off-topic, I guess.

        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