行ごとに N 行と M QTableWidgetItems (チェックボックスとしてのみ使用される) を持つ動的に作成されたテーブルがあります。チェックボックスがオンまたはオフになるたびに、行と列を認識するコードを実行する必要があります。
私の CheckBox サブクラスは次のようになります。
class CheckBox(QTableWidgetItem):
def __init__(self):
QTableWidgetItem.__init__(self,1000)
self.setTextAlignment(Qt.AlignVCenter | Qt.AlignJustify)
self.setFlags(Qt.ItemFlags(
Qt.ItemIsSelectable | Qt.ItemIsUserCheckable | Qt.ItemIsEnabled ))
def stateChanged(self):
do_something(self.row(),self.column())
...
明らかに、これは SIGNAL('stateChanged(int)')
-thingy が発生したときに呼び出される関数を再定義しません。なぜなら、何も起こらないからです。
しかし、もしそうなら:
item = CheckBox()
self.connect(item, SIGNAL('stateChanged(int)'), item.stateChanged)
テーブルを作成するループで、エラーが発生します。
TypeError: arguments did not match any overloaded call:
QObject.connect(QObject, SIGNAL(), QObject, SLOT(), Qt.ConnectionType=Qt.AutoConnection): argument 1 has unexpected type 'CheckBox'
QObject.connect(QObject, SIGNAL(), callable, Qt.ConnectionType=Qt.AutoConnection): argument 1 has unexpected type 'CheckBox'
QObject.connect(QObject, SIGNAL(), SLOT(), Qt.ConnectionType=Qt.AutoConnection): argument 1 has unexpected type 'CheckBox
編集:私も再定義を試みましたが、アイテムがチェックされているかチェックされていないときに呼び出されないようsetCheckState()
です。
編集2:さらに、接続を変更する
self.connect(self.table, SIGNAL('itemClicked(item)'),
self.table.stateChanged)
どこtable = QTableWidget()
でも役に立ちません。
これを正しい方法で行うにはどうすればよいですか?