Saturday, January 17, 2015

PySide Tree Tutorial: Introduction

I think that I shall never see

A poem lovely as a tree.
                      -Joyce Kilmer

I've written an annotated companion to the simpletreemodel example that comes with PySide/PyQt. The code builds and displays a hierarchically organized data structure (i.e., a tree) using a model subclassed from QAbstractItemModel. I spread it out over multiple posts (see Table of Contents below). When finished, I'll put the entire series of posts into a single PDF and put a link to it in this post.

In Part I we will briefly review the model/view framework, focusing on details relevant for implementing our example. In sections II and III, we will study simpletreemodel. Part IV includes suggestions for future study. Part V shows how you can use other tools (QTreeWidget and QStandardItemModel) to construct a similar tree.

Table of Contents
I:Models and Views
            A. The big picture
            B. The mighty index
II: Building the data structure
            A. An introduction to simpletreemodel
            B. From TreeItem to tree structure
            C. Cross-examining simpletreemodel
III: Making the tree model
            A. Introducing the TreeModel class
            B. QAbstractItemModel's API
            C. Index and parent
            D. Creating the tree with setupModelData()

This started as a direct translation of the online Qt documentation on model-view programming. The main sources used were:
Also, thanks also to the folks at stackoverflow and for answering my many questions. Thanks also to Tim Doty, Anna Stenwick, and Mark Summerfield for comments on previous drafts. Feel free to post questions/suggestions/comments in the comments of the relevant posts, or email them to me: thomson.eric at gmail.

Summerfield, M (2008) Rapid Gui Programming with Python and Qt. Prentice Hall.
Summerfield, M (2010) Advanced Qt Programming. Prentice Hall.


Timm Wagener said...

Great code walk-through, thanks a lot :)

Peter Krywiak said...

Hello Eric,I'm a non-prigrammer trying to write asimple GUI. I got stuck, but your post really helped me out. Very clearly explained for a visual thinking newbie like me.