How and why Qt functions can be overridden

Rodrigo de Salvo Braz rodrigobraz at gmail.com
Sun Aug 29 19:49:55 BST 2021


That's exactly my point: I know I can override a protected non virtual
method, but that would only be "just another method" that will only be
called when explicitly called by me: I could even name it in any other
way, and that won't change anything.
The problem is about methods that are invoked by Qt itself, like those I
reported: QItemDelegate.drawBackground or QComboBox.initStyleOption. If
they are implemented, they are never used by Qt, and can only be explicitly
called by python code.

Yes, I agree.

I don't know Qt in that much detail, but I would hope that, if a method was
not made virtual, it's because the designers thought there would be some
other way of overriding behavior. But it could be that they were simply not
thinking big enough.

As for making a non-virtual method virtual, you're right, I don't think
that's possible at all.

Good luck,

Rodrigo



On Sun, Aug 29, 2021 at 11:12 AM Maurizio Berti <maurizio.berti at gmail.com>
wrote:

> Thank you for your reply, but it doesn't really answer my question.
>
>
>> One thing is that I don't think being public or protected or private is
>>> important for overridden methods. They will behave the same way regardless
>>> as far as virtualness and being overridden are concerned. The only thing
>>> that changes is who can invoke them.
>>>
>>
> That's exactly my point: I know I can override a protected non virtual
> method, but that would only be "just another method" that will only be
> called when explicitly called by me: I could even name it in any other
> way, and that won't change anything.
> The problem is about methods that are invoked by Qt itself, like those I
> reported: QItemDelegate.drawBackground or QComboBox.initStyleOption. If
> they are implemented, they are never used by Qt, and can only be explicitly
> called by python code.
>
> Thank you anyway,
> 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/20210829/98d52ea2/attachment.htm>


More information about the PyQt mailing list