Search code examples
pythonpyqt4maya

Updating cell widgets changes in a Qtable without selecting the cell


well I'm using Pyqt4 in Maya2012 to make a reference editor alike ui. I working with a QtableWidget to make the reference list and i have subwidgets in each cell. One of the widgets is a checkbox that unload or reload the reference. The problem i have is if a click directly in the checkbox without have the cell selected it doesn't do anything

this is my code:

 def listConnections(self):

    self.pos=self.sender().currentRow()

    wid = self.list.ref_l.cellWidget(self.pos, 0).children()

    self.text = self.list.list[self.pos]
    self.ref()

    for wt in wid:
        if type(wt)== type(QCheckBox()):
            wt.stateChanged.connect(self.changeState)

        if type(wt)== type(QComboBox()):
            wt.currentIndexChanged.connect(self.changeType)

I'm calling the function with a "itemSlectionChanged" signal because is the only way i knew i could detect the subwidgets. All the subwidgets are made in the moment i fill the list.

Is there a way to make what i want?

Edit:

This is how i called the function

self.list.ref_l.itemSelectionChanged.connect(self.listConnections)

and this is how i create all the subwidgets in the cells

 def fillList(self):
    mayaRef = self.findRef()

    if len(mayaRef)>0:
        for count in range(0,len(mayaRef)):

            self.ref_l.insertRow(count)

            wid=QWidget()
            cLayout=QHBoxLayout()
            wid.setLayout(cLayout)

            checkWid=QCheckBox()

            nameWid=QLabel()

            cLayout.addWidget(nameWid)

            nameWid2=QLabel()

            cLayout.addWidget(nameWid2)

            comWid=QComboBox()
            cLayout.addWidget(comWid)

            self.ref_l.setCellWidget(count,0,wid)

self.ref_l is my QTable Widget, this is in another code that i'm calling with self.list in the original


Solution

  • You should set up all your connections right after you create the check boxes in fillList. Each item is associated with the path of the reference. You can use a QSignalMapper to map each check box to the path, then connect the signal mapper to your changeState slot. The signal mapper then calls that slot with the path you specified.