The simpletreemodel example that comes with PySide includes the following files:
simpletreemodel.py #the main programThe GUI displays a tree view of the Table of Contents of a Qt Designer tutorial (Figure 3). It provides basic keyboard navigation that is the default in all tree views (e.g., pressing the right arrow expands an item to show its children). Note that each row in the view contains two columns of data: a title (e.g.,'Getting Started') and a summary (e.g., 'How to familiarize yourself with Qt Designer').
simpletreemodel_rc.py #compiled resource file
default.txt #text file of data in GUI
Figure 3: The GUI created by the application |
There are two main classes defined in simpletreemodel.py:
- A home-grown TreeItem class that represents individual rows in the tree. Our data store consists of multiple TreeItem instances connected into a hierarchically organized tree.
- A TreeModel class, subclassed from QAbstractItemModel, that serves as a wrapper for the data structure built out of TreeItems. It implements the API needed by the view (as discussed in post IA).
Before moving on in the tutorial, I strongly recommend that you check to make sure that simpletreemodel runs as expected on your system. If it does not, then feel free to ask for help in the comments.
4 comments:
Do you know how to get simpletreemodel_rc.py from default.txt and simpletreemodel.qrc?
Thanks!
Really helpful.
Anonymous: yes that topic is not covered very often.
To compile the resource file (let's call it resource.qrc) use something like the following command at your system prompt, with the containing folder as your working directory (let's assume you want it to be compiled/saved as resource_rc.py):
pyside-rcc resources.qrc -o resource_rc.py
This assumes the folder containing pyside-rcc.exe is on your system path (you may have to add it yourself).
Anon, this is also covered this some in Pyside Summer chapter 6 of Summerfield's book.
Post a Comment