I would like to connect the activated signal from the QML ListView to the pyqtSlot decorated method from my Python3 / PyQt5 code (5.6).
My current approach is to load a QML scene in my code through QQmlApplicationEngine , and then use findChild() to get a link to my ListView .
The problem is that I can find a ListView when searching for a QObject, for example findChild(QObject, 'myList') . But the htis object does not give me access to the activated signal, most likely because this signal is defined only for QAbstractItemView and its descendants.
So, if I try findChild(QListView, 'myList') , the result will be None . Therefore, I cannot get to the activated signal. Is this a bug in PyQt5 or is there another way to connect to this signal?
Here are some minimal working examples.
list.py:
import sys from OpenGL import GL from PyQt5.QtCore import QUrl, QObject from PyQt5.QtWidgets import QApplication, QListView from PyQt5.QtQml import QQmlApplicationEngine
List.qml:
import QtQuick 2.0 import QtQuick.Window 2.2 Window { visibility: Window.FullScreen visible: true ListView { objectName: "myList" anchors.fill: parent delegate: Item { width: parent.width * 0.8 height: 40 Row { id: row1 Rectangle { width: 40 height: 40 color: colorCode } Text { text: name font.bold: true anchors.verticalCenter: parent.verticalCenter } spacing: 10 } } model: ListModel { ListElement { name: "Grey" colorCode: "grey" } ListElement { name: "Red" colorCode: "red" } ListElement { name: "Blue" colorCode: "blue" } ListElement { name: "Green" colorCode: "green" } } } }
source share