[PyKDE] [PyQt] QListViewItem and repaint

Sok Ann Yap ysa_arsenal at yahoo.com
Mon Jul 7 00:04:01 BST 2003


Hi there

I subclass QListViewItem so that the font will be in green color
when the item is chosen either by double clicking or calling a
function (let's name it as Z)

The color changes properly when I double click or call this
function Z directly (clicking on menu or using accel key).
However, when function Z is used as callback from another
function (i.e. no user interaction), here are the scenarios..

1) if QListView scrolls (I have ensureItemVisible() in function
Z), the color changes
2) if QListView does not scroll, the color remains unchanged
until I physically send a mouse or keyboard event (i.e. move the
mouse pointer into the window border, or shake the mouse pointer
when it was already inside the window, or press any key when the
window is having focus)

Here are parts of the code...

class MyListItem(QListViewItem):
...
...
...
    def isDoubleClicked(self):
        return self.doubleClicked
    
    def setDoubleClicked(self, doubleClicked):
        self.doubleClicked = doubleClicked
        self.repaint()
    
    def paintCell(self, p, cg, column, width, align ):
        if self.isDoubleClicked():
            cg = QColorGroup(cg)
            cg.setColor(QColorGroup.Text, QColor("forest
green"))
        QListViewItem.paintCell(self, p, cg, column,
width,align)

class Gui:
...
...
...
    def Z(self):
        self.prevItem.setDoubleClicked(False)
        self.listView.ensureVisible(self.currentItem)
        self.currentItem.setDoubleClicked(True)

My description is kinda bad but I hope you can understand and
give me some guidance. Thanks!

__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com




More information about the PyQt mailing list