【问题标题】:PyQT4 Combobox changes the list of another combobox [closed]PyQT4 Combobox 更改另一个组合框的列表 [关闭]
【发布时间】:2012-11-21 21:58:53
【问题描述】:

我刚开始使用 pyqt4 并且一直坚持如何从另一个组合框更改组合框列表。是否有某种类型的示例说明如何使用此方法。

我是否使用 if, else 语句来更改 combobox_2 的选项?

例如

Combobox_1 有一个 1,2,3 的列表。 Combobox_2 具有 a,b,c 或 d,e,f 或 g,h,i 的列表。

如果在 Combobox_1 中选择了 1,Combobox_2 会显示 a,b,c。

如果在 Combobox_1 中选择了 2,Combobox_2 将显示 d,e,f。

如果在 Combobox_1 中选择了 3,Combobox_2 将显示 g,h,i。

谢谢

【问题讨论】:

    标签: python combobox pyqt4 qt-designer qcombobox


    【解决方案1】:

    你想做的是这样的:

    def __init__(self):
        ...
        self.items = {'1':['a','b','c'],'2':['d','e','f'],'3':['g','h','i']}
        self.Combobox_1.activated[str].connect(self.on_combo_activated)
        ...
    
    ...
    
    def on_combo_activated(self, text):
        self.Combobox_2.clear()
        self.Combobox_2.addItems(self.items[text])
    

    【讨论】:

    • 太棒了,如果我有三个组合框而不是两个组合框,有什么建议吗?
    • 您可以对第二个组合框中的currentIndexChanged 信号做一些事情。另一种可能性是对第三个组合框中的项目使用第二个字典,将 combobox_2 的所有值作为键,然后执行self.Combobox_3.addItems(self.items_2[self.Combobox_2.currentText()])
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-31
    相关资源
    最近更新 更多