[PyKDE] Custom QListViewItem

Thierry Jouve jouve at esrf.fr
Tue Jul 2 17:37:01 BST 2002


Hi,

I want to create a custom QListViewItem to put it into a QListView
widget.

But I have some problems, and I don't know how to solve it.
I've seen in the C++ source code of QCheckListItem, but this doesn't
help me.

Here is my script. The principal method "paintFocus" doesn't work and I
don't know why.



#!/usr/bin/env python

from qt import *

class ListViewItem(QListViewItem) :

   def __init__(self, parent, text = None) :
      QListViewItem.__init__(self, parent, text)

      self.contents = QLabel(self.listView())

   def setText(self, text) :
      self.contents.setText(text)

   def paintCell(self, qPainter, qColorGroup, column, width, align) :
 
      print "paintCell"

      rect = self.listView().itemRect(self)
      rect.setWidth(width)
      self.contents.setGeometry(rect)
      self.contents.show()

      if (col != 0) :
         QListViewItem.paintCell(qPainter, qColorGroup, column, width,
align)
     

   def paintFocus(self, qPainter, qColorGroup, qRect) :

      print "paintFocus"

      rect = QRect()
      rect.setRect(qRect.x() + 21, qRect.y(),
                   qRect.width() - 21, self.listView().columnWidth(0))
      
      #self.contents.setFrameRect(rect)
      #self.contents.drawContents(qPainter)

      QListViewItem.paintFocus(self, qPainter, qColorGroup, qRect)

   def activate(self) :

      print "activate"

      pass

   def rtti(self) :

      print "rtti"

      return 100349857

if __name__ == "__main__" :
   import sys

   qa = QApplication(sys.argv)
   qlv = QListView()

   lvi1 = ListViewItem(qlv, "Salut") 

   qlv.insertItem(lvi1)

   qlv.show()
   qa.setMainWidget(qlv)
   qa.exec_loop()


Do I have forgot to implement methods ??? Is my code correct ???

Regards,

Python : 2.1.1
Qt : 3.0.2
PyQT : 3.2.4

--
   Thierry JOUVE

   BLISS GROUP - ESRF
   Mail : jouve at esrf.fr, Office : 155b, Tel : 29-46




More information about the PyQt mailing list