[PyKDE] custom widget question

Matt Chambers chambers at imageworks.com
Fri Jan 5 19:06:47 GMT 2007


Hi guys, I'm using a QTreeWidget for this particular tool, and  a custom 
widget which displays a progress bar type image.  Some code:

def paintEvent(self,e):
       
        p = QtGui.QPainter(self)
        rect= e.rect()
        total_frm = self.__profile.frameCount()
        ratio = rect.width() / float(total_frm)
        h_totals = self.__profile.getFrameStatusTotals()
       
        # take this out and works good, but doesn't look as good.
        rect.setY(rect.y() + 2)
        rect.setHeight(rect.height() - 2)
        rect.setY(rect.y() + 1)
        rect.setHeight(rect.height() - 1)
       
        for type in FSTATUS:
            length = int(math.ceil( ratio * h_totals[type]))
            if length > 0:
                rect.setWidth(length)
                p.fillRect(rect,FCOLORS[type])
                rect.setX(rect.x() + length)


Basically, what it does is break down some data and show a type of 
progress bar with sections colored differently.  My problem is that if 
you scroll the image of the bar off the screen and back on, it doesn't 
redraw properly. Depending on the speed you scroll, there is different 
behavior.  Too fast and it leaves out horizontal lines, too slow and it 
leaves artifacts.

If I take out the part where I resize the rect so it does't fill the 
whole cell, its works good.  I also tried redrawing the base color under 
the cell before redrawing the bar.

-Matt




More information about the PyQt mailing list