2

我有一个 pyqtgraph Combobox,其定义如下。

def __init__(self):
    # some other stuff....

    mylist=OrderedDict()
    mylist['1k'] = 1
    mylist['10k'] = 10
    mylist['100k'] = 100
    mylist['1M'] = 1000
    self.myselectorA = ComboBox()
    self.myselectorA.setItems(mylist)
    self.myselectorA.currentIndexChanged.connect(self.selchangedA)

def selchangedA(self):
    self.sq.setA(self.myselectorA.value())
    if self.sq.gainlink:
        self.sq.setB(100./self.myselectorA.value())
        self.viewupdate = True
        self.myselectorB.setValue(100./self.myselectorA.value())
        self.viewupdate = False

附加的回调函数selchangedA做了一些事情,其中​​包括第二个 Combobox ( myselectorB) 的可选更新。此更新取决于另一个变量gainlink

我有一种情况,我需要能够检测到组合框中相同元素的重新选择,以便它更新辅助组合框。这可能吗?

我知道用户应该只在辅助组合框上选择适当的值,但我希望为用户提供最大的灵活性。

4

1 回答 1

4

currentIndexChanged(int)可以将信号activated(int)(如果选择没有改变但选择了元素,也会发出)连接到selchangedA(self, int). 除此之外,您可以将组合框的当前索引保存在单独的变量中,并检查selchangedA该值是否与前一个相同并采取相应措施。

于 2014-09-17T12:11:37.977 回答