no signals from QML if QQuickWidget not constructed with proper parent?

41 Views Asked by At

I have a QTabWidget, and at least one of the tabs contains a QQuickWidget. In my Python code (I'm using PySide6), I'm getting an object from QML and connecting a slot to one of its signals like this:

self._listView = self._ui.diagramQuick.rootObject().findChild(QObject, "listView")
self._listView.currentIndexChanged.connect(self._selectedItemChanged)

This used to work in a previous version where there was no tab widget and the QQuickWidget was parented to the main window widget. However, the QTabWidget docs state that the widgets for the individual tabs should be created without a parent (they are automatically reparented to the tab widget). If I do that, self._selectedItemChanged is never called. The only way to fix this is to construct the tabs with a parent that is in the object hierarchy, so

self._ui.tabWidget.addTab(TabPage(self), "text")

Using a dummy widget as a parent does not work:

self._test = QWidget()
self._ui.tabWidget.addTab(TabPage(self._test), "text")

Am I missing some crucial piece of documentation, or is this a bug in Qt?

0

There are 0 best solutions below