Discussion:
[PySide] checking for installedent event filters
Frank Rueter | OHUfx
2018-07-21 05:09:54 UTC
Permalink
Hi,

I have an interesting scenario where I need to install an event filter
on the fly from inside another event filter.

This is because the widget I install the first event filter on changes
it's window() inside the main application under certain circumstances
(out of my control), and I need to know about the widget.window()'s move
event in order for the main event filter to work properly.

Anyway, to avoid installing the same filter multiple times I currently
do this inside the first event filter:
    def eventFilter(self, obj, event):
        if event.type() == QtCore.QEvent.UpdateRequest:
            # obj.window() may or may not have change at this stage
            obj.window().removeEventFilter(self.window_ef)
            obj.window().installEventFilter(self.window_ef)

Is there a better way? I.e. is there a way to check which event filters
are already installed?

Cheers,
frank
David Anes
2018-07-21 14:59:39 UTC
Permalink
Hi Frank,

I would track the window object on my own on every call to the event
filter, and if it's different, then do the removeEventFilter from the old
one, installEvent on the new one and update the tracked object.

Cheers,
David.
Hi,
I have an interesting scenario where I need to install an event filter on
the fly from inside another event filter.
This is because the widget I install the first event filter on changes
it's window() inside the main application under certain circumstances (out
of my control), and I need to know about the widget.window()'s move event
in order for the main event filter to work properly.
Anyway, to avoid installing the same filter multiple times I currently do
# obj.window() may or may not have change at this stage
obj.window().removeEventFilter(self.window_ef)
obj.window().installEventFilter(self.window_ef)
Is there a better way? I.e. is there a way to check which event filters
are already installed?
Cheers,
frank
_______________________________________________
PySide mailing list
http://lists.qt-project.org/mailman/listinfo/pyside
--
David "kraptor" Anes Alcolea
* @kraptor <http://twitter.com/kraptor>
* linkedin.com/in/davidanes
<http://simlaps.com>
Frank Rueter | OHUfx
2018-07-23 00:57:20 UTC
Permalink
Ah yes, good point. That sounds much cleaner, thanks!

Cheers,
frank
Post by David Anes
Hi Frank,
I would track the window object on my own on every call to the event
filter, and if it's different, then do the removeEventFilter from the
old one, installEvent on the new one and update the tracked object.
Cheers,
David.
Hi,
I have an interesting scenario where I need to install an event
filter on the fly from inside another event filter.
This is because the widget I install the first event filter on
changes it's window() inside the main application under certain
circumstances (out of my control), and I need to know about the
widget.window()'s move event in order for the main event filter to
work properly.
Anyway, to avoid installing the same filter multiple times I
            # obj.window() may or may not have change at this stage
            obj.window().removeEventFilter(self.window_ef)
            obj.window().installEventFilter(self.window_ef)
Is there a better way? I.e. is there a way to check which event
filters are already installed?
Cheers,
frank
_______________________________________________
PySide mailing list
http://lists.qt-project.org/mailman/listinfo/pyside
<http://lists.qt-project.org/mailman/listinfo/pyside>
--
David "kraptor" Anes Alcolea
* linkedin.com/in/davidanes <http://linkedin.com/in/davidanes>
Loading...