我有一个分层的两个组合框。第一个组合框显示customerNames的列表,即与MySQL数据库不同的公司。每个客户在不同的城市都有分支机构。
然后,当从组合框1选项列表中为该特定客户选择客户名称时,城市/分支机构的列表自动显示在组合框2中。类似这样的东西,例如:
combo1: chosen_customer [Aldi] --> cities:{NY, Boston, Berlin, Tokyo, London} then..
combo2: options {NY, Boston, Berlin, Tokyo, London}当我们再次选择另一个客户时,问题就来了,这个客户最终拥有较少的分支机构--例如
combo1: chosen_customer [Meyer] --> {LA, San Francisco}, then.. we got
combo2: options {LA, San Francisco, Berlin, Tokyo, London}
intead of combo2: options {LA, San Francisco}下面是运行combo2的函数,每次从列表combo1中选择一个customerName时都会调用该函数:
def loadComboCity(self,customerName):
"""query results cityList into self.mydb.matrix"""
queryName="citylist_thisCustomer"
self.mysqlAPI(queryName,customerName)
id=0
for row in self.mydb.matrix:
cityname=self.mydb.matrix[id][0]
self.addcomboCity(id,cityname)
id=id+1
del self.mydb.matrix[:]以及添加属于该客户的列表城市的每个名称的函数:
def addcomboCity(self,id,cityname):
self.comboCity.addItem(QtCore.QString())
self.comboCity.setItemText(id, QtGui.QApplication.translate("MainWindow", cityname, None, QtGui.QApplication.UnicodeUTF8))我们尝试使用del来清理列表的前一个内容,但它仍然获得相同的行为。
这是一个与Qt还是Python相关的问题?或者我们在这里遗漏了一些东西?
所有的意见和建议都是非常感谢的。
发布于 2010-01-03 02:31:52
我想你遗漏了一个QComboBox.clear()调用,在'for循环‘之前。尝试下面的代码(注意id=0之前的新行)
def loadComboCity(self,customerName):
"""query results cityList into self.mydb.matrix"""
queryName="citylist_thisCustomer"
self.mysqlAPI(queryName,customerName)
# Clear the previous items in the combobox (if any)
self.comboCity.clear()
id=0
for row in self.mydb.matrix:
cityname=self.mydb.matrix[id][0]
self.addcomboCity(id,cityname)
id=id+1
del self.mydb.matrix[:]https://stackoverflow.com/questions/1990782
复制相似问题