[PyKDE] Re: Shading after QListView.setSelected()

Jeffrey Barish jeff_barish at earthlink.net
Tue Mar 29 17:02:17 BST 2005

Phil Thompson wrote:

>> This question has to be something simple, but I just started
>> programming
>> PyQt.  I fill a listview with lines of text then select the first
>> line
>> with QListView.setSelected(QListView.firstChild(), True).  The
>> appropriate item is shaded, but the shading is grey rather than blue.
>> I figure that means that the item is not enabled.  Right so far?  So
>> I
>> tried QListView.firstChild().setEnabled(True).  I get an
>> AttributeError.  The Qt documentation says that
>> QListView.firstChild() returns a QListViewItem and that QListViewItem
>> has an attribute
>> setEnabled.  Is this a bug?  Using isEnabled() also produces an
>> AttributeError.
> Can you post a small, complete example that demonstrate's the problem
> - and the text of the exception?
> Phil
I subclassed QListViewItem to provide a place to stash some data.  I
printed self.firstChild() to confirm that it is a MyListViewItem.  I
did dir(QListViewItem) to confirm that there really is no attribute
setEnabled.  Here's the code that calls setEnabled():

class MyListView(QListView):
    def getSelections(self):
        for thing in self.things:
            lvi = MyListViewItem(self, thing['data'])
            for col, key in zip(range(len(self.keys)), self.keys):
                lvi.setText(col, thing['text'])

        self.setSelected(self.firstChild(), True)
        self.firstChild().setEnabled(True)  # produces AttributeError

class MyListViewItem(QListViewItem):
    def __init__(self, parent, data):
        QListViewItem.__init__(self, parent)
        self.data = data

    def getItemData(self):
        return self.data

I am using python 2.4 (the kopsis package).
Jeffrey Barish

More information about the PyQt mailing list