I want to create an event (print in this case) based on which combox and which row in the combox. I had a look on this old post and made some extension. Does it make some sense? When I press "second" in the left combox I want the output "0, 2" and when I press the "second" in the right combox I want the output "1, 2".
from PyQt4 import QtCore, QtGui
import sys
class MyClass(object):
def __init__(self, arg):
super(MyClass, self).__init__()
self.row = arg
self.col = []
def add_column(self, col):
self.col.append(col)
class myWindow(QtGui.QWidget):
def __init__(self, parent=None):
super(myWindow, self).__init__(parent)
comboBox = [None, None]
myObject = [None, None]
slotLambda = [None, None]
for j in range(2):
comboBox[j] = QtGui.QComboBox(self)
if j > 0:
comboBox[j].move(100, 0)
test = [['first', 1], ['second', 2]]
myObject[j] = MyClass(j)
for num, value in test:
comboBox[j].addItem(num)
myObject[j].add_column(value)
slotLambda[j] = lambda: self.indexChanged_lambda(myObject[j])
comboBox[j].currentIndexChanged.connect(slotLambda[j])
@QtCore.pyqtSlot(str)
def indexChanged_lambda(self, string):
print string.row, string.col
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
app.setApplicationName('myApp')
dialog = myWindow()
dialog.show()
sys.exit(app.exec_())