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

Jeffrey Barish jeff_barish at earthlink.net
Tue Mar 29 19:32:26 BST 2005

Hans-Peter Jansen wrote:
> Since your sample code isn't complete in this form, it's hard to tell
> you _anything_. Do you really expect us to form something runable
> from your artifacts to prove you right or wrong?
> Pete
Well, yes.  I actually thought that my mistake was so basic that it
would be obvious even in this fragment.  Sorry.  Here's a complete
sample which I tried to make as short as possible.  I even eliminated
the subclassing (of QListViewItem), which is what I thought might be
producing the problem.  When I uncomment the line with the setEnabled
call, I get an attribute error.  I should also mention that with this
sample, the selection (after setSelected) is not gray.  Trying to get
the shading to blue was what led me to this problem in the first place. 
At this point, I don't know what it is in the full program that changes
the shading to gray.  Does the gray shading mean that the item is

import sys
from qt import *

class MainWindow(QMainWindow):
    def __init__(self, *args):
        QMainWindow.__init__(self, *args)

        self.mainWidget = QWidget(self)
        self.mlv = MyListView(self.mainWidget)
        self.vlayout = QVBoxLayout(self.mainWidget)


class MyListView(QListView):
    def __init__(self, parent):
        QListView.__init__(self, parent)

    def update(self):
        for key in ['one', 'two', 'three']:
            self.addColumn(key, 80)

        for thing in [['isaone', 'isatwo', 'isathree'],
                  ['isanotherone', 'isanothertwo', 'isanotherthree'],
                  ['yetanotherone', 'yetanothertwo', 'yetanotherthr']]:
            lvi = QListViewItem(self)
            for col in range(3): lvi.setText(col, thing[col])

        item = self.firstChild()
        self.setSelected(item, True)
        print 'item = ', item   # it's a QListViewItem (that's right)
##        item.setEnabled(True) # produces AttributeError (that's wrong)

def main(args):
    app = QApplication(args)
    win = MainWindow()
    app.connect(app, SIGNAL("lastWindowClosed()"), app, SLOT("quit()"))

if __name__ == "__main__":

Jeffrey Barish

More information about the PyQt mailing list