PyQt5 QML treeview示例

2024-06-16 19:09:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试用PyQt5.6(python3.4)和QML设置一个简单的treeview示例。我刚刚发现了一些C++例子,但是没有什么与PyQT相关的。我选择了与PyQt源代码一起使用的simpletreemodel示例并对其进行了修改(https://github.com/baoboa/pyqt5/tree/master/examples/itemviews/simpletreemodel)。在

很可能是模型出了问题。我收到两条错误信息:

simpletreemodel.qml:13:5: QML TreeView: Binding loop detected for property "model"

...qt/5.6/gcc_64/qml/QtQuick/Controls/TreeView.qml:94:16: Unable to assign [undefined] to QAbstractItemModel*

你知道发生什么事了吗?qmltreeview刚刚在qt5.5中引入,也许它在PyQt中还不能完全工作?!没有找到任何相关信息。在

这是我的代码:

在simpletreemodel.qml在

import QtQuick 2.5
import QtQuick.Controls 1.4
import QtQml.Models 2.2

Rectangle {
    width: 480
    height: 640

    TreeView {
        id: treeView
        anchors.fill: parent
        anchors.margins: 6
        anchors.top: parent.top
        anchors.horizontalCenter: parent.horizontalCenter

        model: model

        TableViewColumn {
            title: "Title"
            role: "TitleRole"
            resizable: true
        }

        TableViewColumn {
            title: "Summary"
            role: "SummaryRole"
            resizable: true
        }
    }
}

在simpletreemodel.py在

^{pr2}$

Tags: toimport示例modeltopqmlpyqtparent