Skip to content

Instantly share code, notes, and snippets.

@sametz
Created March 28, 2017 01:10
Show Gist options
  • Save sametz/a4f2cc8557e73b32fd45d7c66d16fb66 to your computer and use it in GitHub Desktop.
Save sametz/a4f2cc8557e73b32fd45d7c66d16fb66 to your computer and use it in GitHub Desktop.
Determine list of parents of a PyQt5 object
def test_child_parent_map(self):
va_widget_fetch = self.ui.findChild(QDoubleSpinBox, 'va') # look up a widget by objectName
current_widget = va_widget_fetch
end = False
while not end:
try:
print('Widget ', current_widget.objectName(), ' has parent ',
current_widget.parent().objectName())
current_widget = current_widget.parent()
except:
print('The parent of', current_widget.objectName(),
'is of type', type(current_widget.parent()))
print('No more parents.')
end = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment