如何使用PyQt5从python访问QML TableView选择属性

2024-09-29 21:34:56 发布

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

我想使用PyQt5获得QML表视图选择的Python表示。我还没有找到一个简单的解决办法。在

假设以下示例文件:

main_窗口.qml

ApplicationWindow {
    // ...

    signal selectionChanged()

    property alias tableSelection: tableView.selection

    TableView{
        id: tableView

        model: []

        selectionMode: SelectionMode.ContiguousSelection
        selection.onSelectionChanged: selectionChanged()
    }
}

main_窗口.py

^{pr2}$

get_table_selection()返回一个QObject,这不是我想要的。在

如果可能,我希望将表选择作为(选定的)索引的Python列表来访问。这可能吗?如果是,最好的方法是什么?在

提前谢谢你的帮助。在


Tags: 文件视图示例signalmainaliaspropertyqml

热门问题