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. QWidgetWindow as QObject in event filter with Qt5
Forum Updated to NodeBB v4.3 + New Features

QWidgetWindow as QObject in event filter with Qt5

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 5.5k 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.
  • J Offline
    J Offline
    jurik
    wrote on last edited by
    #1

    Hello,
    in Qt4 I was using event filtering for whole QApplication by calling

    @application->installEventFilter(this)@

    supposing "this" has implemented function

    @bool eventFilter(QObject * o, QEvent * e )@

    In this eventFilter function I was comparing this QObject * o with some another QWidget *, because the goal was to filter every event for every widget, excluding some selected widgets.

    But after the conversion to Qt5 the QObject * o, which is passed to eventFilter function is no longer of type QWidget as it was before, but is instead of type QWidgetWindow, which has this QWidget as a private member. Also, this QWidgetWindow and its header seems to me to be some sort of private class not intended for including in user code. Has someone any suggestions, how to solve this problem? Is there a way how to get the "original" QWidget from QWidgetWindow? Or is there some other way of knowing for which widget is event intended?

    Any help will be very appreciated and I kindly thank you in advance.
    Jurik

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Anticross
      wrote on last edited by
      #2

      Maybe @bool QObject::isWidgetType() const@ or @bool QObject::isWindowType() const@ can help.

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        zeljko
        wrote on last edited by
        #3

        I don't think that he's talking about testing if passed QObject is QWidget or not. He is talking about change in installed event filter: It does not pass QWidget anymore but QWidgetWindow which does not publish QWidget for which event is currently in installed event filter.If it's so, then it's pretty ugly change in Qt5. I'm using Qt4 in same way, but won't go to Qt5 if it's so.
        @Jurik, but QWidget have windowHandle() in Qt5 ? If you iterate through widgets then ask for it's window handle and compare it with QObject from event.

        1 Reply Last reply
        0
        • R Offline
          R Offline
          rip_
          wrote on last edited by
          #4

          You probably found the answer you are looking for by now. But for others, this is what I'm seeing.

          The eventFilter() method is getting called several times for each event (as the event passes through the tree). The first call the object is a QWidgetWindow, the second call it's the object I'm looking for. So, try something like the following. Not the best code, but you should get the idea.

          @
          bool MyEvtFilter::eventFilter(QObject * o, QEvent * e)
          {
          if ((e->type() == QMouseEvent::MouseButtonPress) ||
          (e->type() == QMouseEvent::MouseButtonRelease))
          {
          if (o->inherits("QWidgetWindow") )
          {
          // ignore these
          return QObject::eventFilter(o, e);
          }
          else if (o->inherits("MySpecialWidget") )
          {
          // do my stuff
          return true;
          }
          }
          return QObject::eventFilter(o, e);
          }
          @

          1 Reply Last reply
          0
          • R Offline
            R Offline
            rip_
            wrote on last edited by
            #5

            You probably found the answer you are looking for by now. But for others, this is what I'm seeing.

            The eventFilter() method is getting called several times for each event (as the event passes through the tree). The first call the object is a QWidgetWindow, the second call it's the object I'm looking for. So, try something like the following. Not the best code, but you should get the idea.

            @
            bool MyEvtFilter::eventFilter(QObject * o, QEvent * e)
            {
            if ((e->type() == QMouseEvent::MouseButtonPress) ||
            (e->type() == QMouseEvent::MouseButtonRelease))
            {
            if (o->inherits("QWidgetWindow") )
            {
            // ignore these
            return QObject::eventFilter(o, e);
            }
            else if (o->inherits("MySpecialWidget") )
            {
            // do my stuff
            return true;
            }
            }
            return QObject::eventFilter(o, e);
            }
            @

            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