[qutebrowser] Why does TabWidget's parent changes during execution?

Jay Kamat jaygkamat at gmail.com
Sat Aug 4 18:37:53 CEST 2018


Javier Ayres writes:

> 1- In TabbedBrowser's __init__ method, self.widget is set to
> "tabwidget.TabWidget(win_id, parent=self)". With pdb, I can verify
> immediately after that self.widget.parent() correctly returns the
> TabbedBrowser instance.
> 2- Later, at the point of executing browsertab.create, the TabWidget
> instance is passed down as the "parent" argument, but if I do
> parent.parent(), I receive a MainWindow instance instead.

I'm not sure about this, but I'm pretty sure that the parent/child
relationship can be changed by qt depending on the layout of the elements. I
don't think it's a good idea to rely on it being set like that, especially
because it's pretty easy to change the parent/child relationship and not
realize that you're breaking the code that depends on a child/parent being a
certain type of object.

> I have verified with pdb that in both cases it's the same instance of
> TabWidget, and I have re-defined TabWidget.setParent method to make it
> throw an exception in case it was being called somewhere, but it is
> definitely not.
>
> I basically need to access the TabbedBrowser instance down from an
> AbstractTab instance, and this seemed like a clean way of doing so
> without passing new arguments to objects constructors.


how about:
tab-browser = objreg.get('tabbed-browser', scope='window', window=self.win_id)

At some point though, I think that passing the argument in might be cleaner,
especially if you need it a lot of times.


-Jay



More information about the qutebrowser mailing list