Customizing List View Items

Challenge: Fill in the gaps in the code.

Subclassing QListViewItem

To draw custom list view items, we need to subclass QListViewItem:

{{{from qt import QBrush, QFont, QFontMetrics, QListViewItem, QPen, Qt

class ListViewItem(QListViewItem):

}}}

Painting

The paintCell method allow us to draw the list view items in our preferred style. We can always use the QListViewItem base class to draw anything we are unsure about:

{{{ def paintCell(self, painter, colour_group, column, width, alignment):

}}}

Highlighting items

We can highlight the text in a particular column by calling a custom method. This just changes the pen and brush colours for the text in that column:

{{{ def setHighlighted(self, column, enable):

}}}

Other issues

The font needs to be set for the text in any new columns that are created:

{{{ def setText(self, column, text):

}}}

CustomListViewItems (last edited 2009-04-14 07:27:23 by localhost)