[PyQt] Qtreeview/QDirmodel with check-boxes
Jon Noble
jonnobleuk at gmail.com
Mon May 31 01:07:43 BST 2010
Hi,
I'm trying to create a file-system tree-view with checkboxes yet i'm having
great difficulties on doing so.
I found a link (http://lists.trolltech.com/qt-interest/2005-08/msg00516.html)
but I'm not really sure what the solution is. I've tried one solution which is
to use QDirModel.setData() but that makes no difference.
Here's a snippet of my code.
def __fileview_setup(self):
"""
Make the fileview the correct type
"""
index = QModelIndex()
dir_model = QDirModel()
filters = QDir.AllDirs|QDir.Readable|QDir.NoDotAndDotDot
dir_model.setData(index, Qt.Checked, Qt.CheckStateRole)
dir_model.setFilter(filters)
dir_model.setReadOnly(True)
# self.collection_view is a QTreeView
self.collection_view.setModel(dir_model)
self.collection_view.setColumnHidden(1, True)
self.collection_view.setColumnHidden(2, True)
self.collection_view.setColumnHidden(3, True)
self.collection_view.expandToDepth(0)
The file-system view part works fine, just no checkboxes.
Any help would be greatly recieved, thanks.
Jon
More information about the PyQt
mailing list