Thanks for your quick reply. I thought that it was possible to have multiple inheritance in Python.

My original problem was to have a checkbox item in a table cell which could emit a signal when clicked. What I've done is to make a QObject data member as part of my CheckBoxItem class. Is this the only way to get this class to emit a signal when clicked?

My class looks as follows:
class CheckBoxTableItem(QTableItem):
    def __init__(self, parent, table, text):
        QTableItem.__init__(self, table, QTableItem.Always, text)
        self.emitter = QObject(parent)
        self.checkbox = None

    def setContentFromEditor(self, w):
        print 'CheckBoxTableItem::setContentFromEditor ' #DFD
        if self.checkbox:
            self.setText(self.checkbox.text())

    def createEditor(self):
        print 'CheckBoxTableItem::createEditor ' #DFD
        self.checkbox = QCheckBox(self.table().viewport())
        self.checkbox.connect(self.checkbox, SIGNAL("clicked()"), self.__Clicked)
        self.checkbox.setText(self.text())
        self.checkbox.show()
        return self.checkbox

    def __Clicked(self):
        self.emitter.emit(PYSIGNAL("Clicked()"), ())

It's created as follows:
        checkItem = CheckBoxTableItem(self, self.testStatusTable, "Start")
        self.connect(checkItem.emitter, PYSIGNAL("Clicked()"), self.__CheckItemClicked)

        self.testStatusTable.setItem(row, 0, checkItem)

Cheers

Daryl



Phil Thompson wrote:
On Wednesday 26 April 2006 7:44 am, Daryl Dusheiko wrote:
  
Hi,

I would like to add a CheckBox to a cell in a QTable that sends a signal
when the check box is clicked. The existing QCheckTableItem does not
emit any signals.

I've specialised the class from both the QTableItem and QObject classes.
When I create the new class and add the item to the table I get the
following error:

   File "/home/daryld/BurninTest/BurninTestDialog.py", line 29, in __init__
29, in __init__
    QTableItem.__init__(self, table, edittype, text)
 TypeError: argument 2 of QObject() has an invalid type


My class looks as follows:
class CheckBoxTableItem(QObject, QTableItem):
    def __init__(self, table, edittype, text):
        QObject.__init__(self)
        QTableItem.__init__(self, table, edittype, text)  # !!! THIS IS
LINE 29 !!!
        self.checkbox = None

    def setContentFromEditor(self, w):
        if self.checkbox:
            self.setText(self.checkbox.text())

    def createEditor(self):
        self.checkbox = QCheckBox(self.table().viewport())
        self.checkbox.connect(self.checkbox, SIGNAL("clicked()"),
self.__Clicked)
        self.checkbox.setText(self.text())
        self.checkbox.show()
        return self.checkbox

    def __Clicked(self):
        self.emit(PYSIGNAL("Clicked()"), ())


The code where the object is created and is added to the table looks as
follows:
        checkItem = CheckBoxTableItem(self.testStatusTable,
QTableItem.Always, "Start")
        self.connect(checkItem, SIGNAL("clicked()"),
self.__CheckItemClicked)

        self.testStatusTable.setItem(row, 0, checkItem)

Please could someone help me get rid of this error or suggest another
way to get a signal when I click a check box in a table cell.
    

You can't inherit from more than one wrapped class at a time.

Phil

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________
  
begin:vcard
fn:Daryl Dusheiko
n:Dusheiko;Daryl
adr:;;65 Johnston St;Annandale;NSW;2038;Australia
email;internet:[EMAIL PROTECTED]
tel;work:+ 61 2 9562 9858
tel;fax:+61 2 9518 7620
url:http://www.magtech.com.au
version:2.1
end:vcard

_______________________________________________
PyKDE mailing list    [email protected]
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde

Reply via email to