Python Hierarchical QcomboBox:清理列表
我有一个分层的两个组合框。第一个组合框显示 customerNames 列表,即来自 MySQL 数据库的不同公司。每个客户在不同的城市都有分支机构。
然后,当从组合框1选项列表中选择客户名称(例如,{Aldi、Meyer、Carrefour、WalMart})时,对于该特定客户,城市/分支机构的列表将自动显示在组合框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}
这是运行组合2的函数,每次从列表组合1中选择客户名称时都会调用该函数:
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 相关的问题?或者我们在这里遗漏了一些东西?
高度赞赏所有意见和建议。
I have a hierarchical two combo-box. The first combo-box displays a list of customerNames, i.e. different companies from a MySQL db. Each customer has branches in different cities.
Then, when a customer name is chosen from combo-box1 option list, e.g. {Aldi, Meyer, Carrefour, WalMart}, for that particular customer, a list of cities/branches is automatically displayed in the combo-box2. Something like that, e.g.:
combo1: chosen_customer [Aldi] --> cities:{NY, Boston, Berlin, Tokyo, London} then..
combo2: options {NY, Boston, Berlin, Tokyo, London}
The problem comes when we chose again another customer, that eventually has a smaller number of branches - e.g.
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}
Here is the function that runs the combo2, which is called every time a customerName is chosen from the list combo1:
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[:]
and the function that adds each name of the list city that belongs to that customer:
def addcomboCity(self,id,cityname):
self.comboCity.addItem(QtCore.QString())
self.comboCity.setItemText(id, QtGui.QApplication.translate("MainWindow", cityname, None, QtGui.QApplication.UnicodeUTF8))
We tried to use del to clean the previous content of the list, but it still gets the same behavior.
This is a Qt or a Python related problem? Or there is some bit that we are missing here?
All comments and suggestions are highly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您在“for 循环”之前缺少 QComboBox.clear() 调用。尝试以下代码(注意 id=0 之前的新行)
I think you are missing a QComboBox.clear() call , before the 'for loop'. Try the following code (Notice the new line just before id=0)