QYolk I - List widgets in PyQt4
How to use list widgets in PyQt4In QT4 and PyQT4 we have 3 list widgets - List View is a simple list, Tree View and a Table View. Those widgets are available as parts of the lists framework or as "plain" widgets (Model and Item Based) We will use the second option - "Item Based": For this example I used Tree View. When you right-click on the widget a menu will appear with "Edit Items" option, which allows us to add columns to the widget. The important thing is that each column has it number starting from 0.: When you look at QTreeWidget documentation note that it inherits QTreeView, which has a lot of useful methods.
QYolkOn cheeseshop there is Yolk for managing installed with easy_install Python modules. Install it with:
easy_install yolkAnd then:
yolk -lAnd you will see all installed packages. We will make such list in PyQT4 with QTreeWidget. The data will be provided by: The get_distributions method returns a generator with package name + version and package status (Active/not-active). I've made a simple GUI in QTDesigner with a QTreeWidget (name treeList) in a window named QYolk. I've saved the GUI as qyolk.ui and generating qyolk.py: Here is a base version of start.py: The setColumnWidth is from QTreeView and it sets the column widths. "0" is the first column, and "1" is the second one. Now we need to add items to the list. We have to use QTreeWidgetItem: QTreeWidgetItem requires a QTreeWidget to which the item should be added. Method setText(Column ID, Text) is used to set the text of a column. For lists or generators we use a loop, start.py: And the list is read. We can extend the application with more features. For example setTextColor (for QTreeWidgetItem) changes the text colour. Why not make not active packages grey?: setTextColor(Column ID, QtGui.QColor(R, G, B)) - Where R, G, B is a colour in the RGB notation. Finally, I got a PyQT4 application that looks like this: