[PyQt] Model/View programming and QFileSystemModel

Gaëtan Podevijn gpodevij at gmail.com
Mon Nov 15 07:14:10 GMT 2010


I'm trying to understand the model/view programming while making a kind of
tag-based browser. I have some absoluteFilePath in a database associated to
one ore more tags (which are strings) . I'm trying to display those files
(or directories of course) in a view. Hence, I created a subclass of
QFileSystemModel but I'm a little bit lost...

I overredided the data() method which, if I have understood, is used to give
the data to display to the view. I have done things like :

def data(self, modelIndex, role=Qt.DisplayRole):
        if not modelIndex.isValid():
            return QVariant()
        if modelIndex.row() >= len(self.files_list):
            return QVariant()
        return self.files_list[modelIndex.row()]

where files_list is a list of QFileInfo. I've also tried to return only the
name of the file but it is not working. In clear, I'd like to do something

files_list = ['file1', 'file2', 'dir1'] # Of course, those files
aren't systematically in the same directory
model = MyFileSystemModel(files_list)

I'm quite sure I didn't understand exactly how it works. Indeed, how the
view could display the right icon (a dir-icon or a file-icon).

Could someone explains me how should I do ? I'm not asking code, I only want
to understand how model/programming works and how should I do to display a
specific list of files. I read the documentation about model/view
programming but it still obscure for me.

Thank you by advance,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20101115/0c8d5ac2/attachment.html>

More information about the PyQt mailing list