python - 如何为 QListWidget 设置模型

标签 python pyqt

有没有办法为QListWidget 设置模型?我得到 AttributeError: QListWidget.setModel is a private method 对此:

class Model(QtCore.QAbstractListModel):
    def __init__(self):
        QtCore.QAbstractListModel.__init__(self)
        self.items=[]
    def rowCount(self, parent=QtCore.QModelIndex()):
        return len(self.items)
    def flags(self,index):
        return QtCore.Qt.ItemIsEditable

view=QtGui.QListWidget()

viewModel=Model()
view.setModel(viewModel)

最佳答案

我不认为你可以为 QListWidget 设置模型。因为 QListWidget 有自己的模型。但是你可以使用QListView,你可以将自己的模型设置为QListView

关于python - 如何为 QListWidget 设置模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25876487/

相关文章:

python - 在 Pandas 数据框中对重复的列 ID 进行分组

python - PyQt QThreads 通信

python - 如何制作动态组合框PYQT5

python - Quickbase模块add_record()函数——文件上传参数?

python - 如何使用 M2Crypto 从 .pem 文件加载受密码保护的私钥?

python - tensorflow -运行时错误 : Cannot get value inside Tensorflow graph function

python - sendgrid 如何跟踪单个电子邮件

python - QFileDialog - PyQt4/PyQt5/PySide 之间的区别

python - QGraphicsTextItem 从右到左文本

pyqt - 如何在 PyQt 中正确对齐右键单击上下文菜单?