[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
disabled?

import sys
from qt import *

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

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

        self.mlv.update()

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

    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.setMainWidget(win)
    win.show()
    app.connect(app, SIGNAL("lastWindowClosed()"), app, SLOT("quit()"))
    app.exec_loop()

if __name__ == "__main__":
    main(sys.argv)

-- 
Jeffrey Barish




More information about the PyQt mailing list