【发布时间】:2020-03-04 15:28:10
【问题描述】:
我正在学习 pyqt 中的模型/视图架构,但是当我按照Using model indexes 指令并尝试编写 pyqt5 样式的演示时,QModelIndex 无法获取子节点信息?
代码:
class DemoB(QPushButton):
def __init__(self):
super().__init__()
self.clicked.connect(self.on_clicked)
def on_clicked(self, checked):
model = QFileSystemModel()
model.setRootPath(QDir.homePath())
parentIndex = model.index(QDir.homePath())
print(parentIndex.data() )
print(parentIndex, model.rowCount(parentIndex), QDir.homePath())
for row in range(model.rowCount(parentIndex)):
index = model.index(row, 0, parentIndex)
print(index, index.data())
结果:
我的文件夹:
【问题讨论】:
标签: python pyqt pyqt5 qfilesystemmodel