1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
   |  
from functools import partial
 
class TestTable(QtGui.QTableWidget):
  def __init__(self,parent=None):
    super(TestTable,self).__init__(parent)
    self.setRowCount(2)
    self.setColumnCount(2)
 
    combo1 = QtGui.QComboBox()
    combo1.addItems(['pomme','banane'])
    combo2 = QtGui.QComboBox()
    combo2.addItems(['brocoli','haricot'])
    combo1.row = 0
    combo2.row = 1
    self.setCellWidget(0,1,combo1)
    self.setCellWidget(1,1,combo2)
    combo1.activated[int].connect(partial(self.changeCombo, combo1))
    combo2.activated[int].connect(partial(self.changeCombo, combo2))
 
  def changeCombo(self, comboBox, index):
    row = comboBox.row
    self.setCurrentCell(row, 0)
 
if __name__=='__main__':
  import sys
  app=QtGui.QApplication(sys.argv)
 
  fen = TestTable()
  fen.show()
  sys.exit(app.exec_()) | 
Partager