.parent() vs. parent class in PowerBar example

Heads up! You've already completed this tutorial.

Jerry_Zhou | 2020-05-11 09:20:01 UTC | #1

I don't understand how the class _Bar can get access to the QDial() object defined in the PowerBarclass by using self.parent(). Shouldn't self.parent()be referring to QWidget, the class it is inheriting from?

https://www.pythonguis.com/courses/custom-widgets/creating-your-own-custom-widgets/


Jerry_Zhou | 2020-05-15 14:50:20 UTC | #2

Nevermind! Turns out parent() in Qt has different relationship then superclass to subclass. Instead it is between object instances, and when _Bar is instantiated within PowerBar, the parent() of _Bar refers to the Powerbar class.


Create GUI Applications with Python & Qt6 by Martin Fitzpatrick — (PyQt6 Edition) The hands-on guide to making apps with Python — Over 15,000 copies sold!

More info Get the book

Well done, you've finished this tutorial! Mark As Complete
[[ user.completed.length ]] completed [[ user.streak+1 ]] day streak
Martin Fitzpatrick

.parent() vs. parent class in PowerBar example was written by Martin Fitzpatrick .

Martin Fitzpatrick has been developing Python/Qt apps for 8 years. Building desktop applications to make data-analysis tools more user-friendly, Python was the obvious choice. Starting with Tk, later moving to wxWidgets and finally adopting PyQt. Martin founded PythonGUIs to provide easy to follow GUI programming tutorials to the Python community. He has written a number of popular Python books on the subject.