EventFilter Delete labeltext pyqt5

Maurizio Berti maurizio.berti at gmail.com
Wed May 5 18:56:23 BST 2021


Il giorno mer 5 mag 2021 alle ore 19:32 Luca Bertolotti <
luca72.bertolotti at gmail.com> ha scritto:

> i have as follow and in the label i never read the text:
> if i comment the  self.label_10.installEventFilter(self) i read the text
>

With "I never read the text" do you mean that it isn't displayed? Please be
more specific in your questions, "read" can mean a lot of things.

Assuming the above (the text is not *displayed*), that's because you're
always returning True (1) from the event filter.
An eventFilter should not always return 1 (or True), but it should always
call the default implementation instead (return super().eventFilter(object,
event)) as some events should **NOT** be handled by the filter, depending
on the event *and* the widget. In this specific case, by always returning
True the result is that you're **ignoring** the paint event of the label,
which is responsible of *drawing* the contents of the label. Calling the
default implementation of the event filter instead ensures that the basic
event filter of QObject calls any other possible event filter, and if the
return value is False that means: the event hasn't been filtered, so
proceed with the default implementation given by the objects event(event)
call. In this case, call the paintEvent.

Maurizio
-- 
È difficile avere una convinzione precisa quando si parla delle ragioni del
cuore. - "Sostiene Pereira", Antonio Tabucchi
http://www.jidesk.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20210505/b17bdb3d/attachment.htm>


More information about the PyQt mailing list