How and why Qt functions can be overridden

Maurizio Berti maurizio.berti at gmail.com
Sun Aug 29 00:31:23 BST 2021


Premise: while I can read and almost always understand C++, I don't really
know a lot about it.

Subclassing and overriding of Qt classes is almost natural to me, but I
still don't understand some aspects about function overriding, since I'm
too accustomed to the "simpler" way of python subclassing.

For instance, many widgets have an initStyleOption that cannot be
overridden (well, it could, but it's never called natively), while a
similar function can be overridden for QStyledItemDelegate.

>From my limited knowledge I can understand that I can override/overwrite a
function in a subclass and be sure that it's called natively by Qt if it's
public or virtual (like the initStyleOption of QStyledItemDelegate), but
this is still a very "foggy" understanding.

For example, I can override all QItemDelegate drawing functions, except for
drawBackground, which is not virtual; this means that if I want to
implement it (because, for some reason, I don't want to use
QStyledItemDelegate), I need to completely port its paint method so that I
can finally call a possibly custom drawBackground.
Is it possible to make it virtual? If not (as I believe it is), then why?
Also, most importantly, why is it not virtual?

I've been thinking about learning C++ for some time now, but that's a long
term project that I will not be able to begin in the near future. I know
that there's a lot of resources around the web on the topic, but it's
difficult to find simple explanations that could satisfy what I believe is
a slightly "basic" question. It's like wanting to understand the basic
principles about boiling liquid, without necessarily studying how molecular
phase transition works.

So, I'd like to ask if anybody can help me shed some light or at least
point out some resources with a basic explanation about why some functions
cannot be overridden, both from "choice" (from the Qt and C++ perspective)
and from "architecture" (due to the sip binding).


Thank you,
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/7d6ae390/attachment.htm>


More information about the PyQt mailing list