[PyKDE] The order of items in QListView

Eiji Katagiri katagiri at teikokupr.co.jp
Wed May 30 09:08:35 BST 2001


When I use QListViewItem, I got an unexpected result.
Here is a simple sample code. In this sample,
the order of items which I add is 'Europe', 'Asia'.
But I got the order of items which is 'Asia', 'Europe'.


#!/usr/bin/env python
"""
    ListView
"""
from tpqt import *

class ListView(QWidget):
    def __init__(self, *args): 
        apply(QWidget.__init__, (self,)+args)
        self.setCaption('listview')
        listview = QListView(self, 'listview')
        listview.addColumn('Country')
        listview.addColumn('Capital')
        listview.setRootIsDecorated(TRUE)
        listview.setSorting(-1)			# Invalid ?
        #
        europe = QListViewItem(listview, 'Europe')
        asia = QListViewItem(listview, 'Asia') 
        #
        QListViewItem(europe, 'Germany', 'Berlin')
        QListViewItem(europe, 'England', 'London')
        QListViewItem(asia, 'Japan', 'Tokyo')
        QListViewItem(asia, 'South Korea ', 'Seoul')
        self.connect(listview, SIGNAL('clicked(QListViewItem*)'),
                        self.display)
        self.connect(listview, SIGNAL('returnPressed(QListViewItem*)'),
                        self.display)
        sz = listview.sizeHint()
        print 'size of listview=', sz.width(), sz.height()
        sz = listview.sizeHint()
        print 'size of listview=', sz.width(), sz.height()
        listview.resize(sz.width(), sz.height())

    def display(self, item):
        if not item: return
        print 'item : count=', item.childCount(), '  depth=', item.depth()
        # depth = 0: parent/ 1: child / 2: grandchild / ...
        for i in range(2):
            t = item.text(i)
            print i, tr2s(t)

a = Application()
w = ListView()
a.setMainWidget(w)
w.show()
a.exec_loop()

--
Environment: Linux 2.1.18 + Qt-2.2.4 + PyQt-2.3 + Python-2.0


Thanks for any help,

Eiji Katagiri






More information about the PyQt mailing list