In the example below I am trying to use the selection's of two separate comboboxes as two arguments of a function. If 3 and 4 are selected an output of 12 should be produced and so on. How do I write this to send the first combo selection as the first argument and the second combo selection as the second argument?
At the moment, both of the connections return a 'multiply() takes exactly 2 arguments (1 given)" error because the two comboboxes are not simultaneously but separately connected to the function.
from PyQt4 import QtCore, QtGui
class Ui_MainWindow(QtGui.QMainWindow):
def setupUi(self):
window = QtGui.QMainWindow(self)
window.table = QtGui.QTableWidget()
window.table.setRowCount(2)
window.table.setColumnCount(1)
window.setCentralWidget(window.table)
def multiply(x, y):
return x * y
combo_x = QtGui.QComboBox()
combo_y = QtGui.QComboBox()
for i in range(1, 10):
combo_x.addItem(str(i))
combo_y.addItem(str(i))
combo_x.activated[int].connect(multiply)
combo_y.activated[int].connect(multiply)
window.table.setCellWidget(0, 0, combo_x)
window.table.setCellWidget(1, 0, combo_y)
desired = []
for x in range(1, 10):
for y in range(1, 10):
desired.append(multiply(x, y))
window.show()
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
ui = Ui_MainWindow()
ui.setupUi()
sys.exit(app.exec_())