【发布时间】:2018-06-12 19:20:30
【问题描述】:
我想根据哪个组合框和组合框中的哪一行创建一个事件(在本例中为打印)。我看了这个old post 并做了一些扩展。有没有道理?当我在左侧组合框中按“秒”时,我想要输出“0, 2”,当我在右侧组合框中按“秒”时,我想要输出“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_())
【问题讨论】:
标签: python pyqt pyqt4 qcombobox