<div dir="ltr"><div>I think I can answer just a little bit of your questions.</div><div><br></div><div>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.</div><div><br></div><div>Another thing is that, even if a method is not virtual, you can still override and use it. Suppose there is a class A with a method foo that is not virtual. If I sub-class A with a new class B with a method foo, then:<br><br></div><div>A& a_ref = B();</div><div>B b = B();</div><div>a_ref->foo(); // calls original A::foo, because a_ref does not "know" this is a B object<br></div><div>b->foo(); // calls overridden method B::foo, because the compiler knows b is a B object.</div><div><br></div><div>Hope that helps...</div><div><br></div><div>Rodrigo<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Aug 28, 2021 at 4:33 PM Maurizio Berti <<a href="mailto:maurizio.berti@gmail.com">maurizio.berti@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr">Premise: while I can read and almost always understand C++, I don't really know a lot about it.<div><br></div><div>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.</div><div><br>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.</div><div><br>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.</div><div><br></div><div>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.</div><div>Is it possible to make it virtual? If not (as I believe it is), then why?<br></div><div>Also, most importantly, why is it not virtual?</div><div><br>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.</div><div><br></div><div>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).</div><div><br></div><div><div><div><br></div><div>Thank you,</div><div>Maurizio<br><div><div><br></div>-- <br><div dir="ltr">È difficile avere una convinzione precisa quando si parla delle ragioni del cuore. - "Sostiene Pereira", Antonio Tabucchi<br><a href="http://www.jidesk.net" target="_blank">http://www.jidesk.net</a></div></div></div></div></div></div></div></div>
</blockquote></div>