[PyKDE] Signals From a QTableItem Subclass

Bob Parnes rparnes at megalink.net
Mon Aug 4 21:42:01 BST 2003


Hello,

Attached is a demo to illustrate a problem I have with trying to
implement a QTableItem subclass. My guide for the implementation
of PCheckTableItem is the source code for QCheckTableItem.

On my system, using the mouse to toggle PCheckTableItem does not move
the selected cell to the item. It does produce the 'valueChange'
signal, but the signal passes the wrong coordinates. Using the keyboard
moves the selected cell, and pressing the spacebar also produces the
'valueChange' signal, but the signal still passes the wrong coordinates.

The problem may well be due to my conversion from C++ to python, but I
cannot identify it, and I don't know how to troubleshoot it. If it
matters, my system runs debian, with the python2.2-qt3c102 package.
Thanks for any help.

Bob Parnes

-- 
Bob Parnes
rparnes at megalink.net
-------------- next part --------------
#!/usr/bin/env python

import sys
from qt import *
from qttable import QTable, QTableItem, QCheckTableItem

class PCheckTableItem(QTableItem):
  def __init__(self,table,name):
    QTableItem.__init__(self,table,QTableItem.Always,'tableItem')
    self.name = name
    self.RTTI = 1001

  def createEditor(self):
    self.cb = QCheckBox(self.table().viewport(),self.name)
    self.cb.setChecked(False)
    QObject.connect(self.cb,SIGNAL('toggled(bool)'),self.table(),
      SLOT('doValueChanged()'))
    return self.cb

  def setContentFromEditor(self,w):
    if w.inherits('QTableItem'):
      w.setChecked(w.isChecked())
    else:
      QTableItem.setContentFromEditor(w)

  def setChecked(self,check):
    self.table().updateCell(self.row(),self.col())
    w = self.table().cellWidget(self.row(),self.col())
    cb = PCheckBox(w)
    if cb:
      cb.setChecked(check)
    
  def isChecked(self):
    w = self.table().cellWidget(self.row(),self.col())
    cb = PCheckBox(w)
    if cb:
      return cb.isChecked()
    
  def rtti(self):
    return self.RTTI

class Form1(QWidget):
  def __init__(self,parent,name,fl = 0):
    QWidget.__init__(self,parent,name,fl)
    self.setCaption(self.tr("Checkbox Test"))
    self.table = QTable(self,"table")
    self.table.setGeometry(QRect(20,20,335,104))
    self.table.setNumRows(2)
    self.table.setNumCols(2)

    self.table.setColumnWidth(0,150)
    self.table.setText(0,0,self.tr('QCheckTableItem'))
    self.table.setText(1,0,self.tr('PCheckTableItem'))
    chkbox1 = QCheckTableItem(self.table,'')
    self.table.setItem(0,1,chkbox1)
    chkbox2 = PCheckTableItem(self.table,'')
    self.table.setItem(1,1,chkbox2)

    self.connect(self.table,SIGNAL("valueChanged(int,int)"),
      self.valueChange)
    self.connect(self.table,SIGNAL("currentChanged(int,int)"),
      self.currentChange)
    self.resize(QSize(396,201).expandedTo(self.minimumSizeHint()))

  def currentChange(self,row,col):
    print 'currentChange at (%d,%d)' % (row,col)

  def valueChange(self,row,col):
    print 'valueChange at (%d,%d)' % (row,col)

if __name__ == "__main__":
  a = QApplication(sys.argv)
  QObject.connect(a,SIGNAL("lastWindowClosed()"),a,SLOT("quit()"))
  w = Form1(None,'chkboxTst')
  a.setMainWidget(w)
  w.show()
  a.exec_loop()


More information about the PyQt mailing list