【问题标题】:How to show items in QcomboBox depends on second QcomboBox selected item如何在 QcomboBox 中显示项目取决于第二个 QcomboBox 选定项目
【发布时间】:2020-06-30 18:50:24
【问题描述】:

我有两个组合框和 3 个列表,如下所示。

list1 = ['one','two'] list2 = ['a','b'] list3 = ['1','2']

我使用 addItems(list1) 将 list1 添加到第一个组合框中 问题是我想显示,如果我在第一个 Qcombobox 中选择“一个”,那么第二个 Qcombo 框应该显示“list2”,如果我选择“两个”,应该显示“list3”。请告诉我该怎么做。

谢谢。

【问题讨论】:

    标签: python-3.x qcombobox


    【解决方案1】:

    我用了两种方法来解决,

    1. currentIndexChanged
    2. currentIndex()

    调用方法如下:

    
    list1 = ['one','two']
    comboBox_1.addItems(list1)
        
    comboBox_1.currentIndexChanged.connect(self.item_name)
    
    def item_name(self):
        list2 = ['a','b'] 
        list3 = ['1','2']
        
        if comboBox_1.currentIndex() == 0:
            comboBox_2.addItems(list2)
        
        elif comboBox_1.currentIndex() == 1:
            comboBox_2.addItems(list3)
    

    除了选择索引,您还可以使用self.posten.currentText() == "one":

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-23
      • 2019-10-26
      • 1970-01-01
      • 2015-11-11
      • 2019-07-08
      • 2012-03-29
      • 1970-01-01
      相关资源
      最近更新 更多