PyQt QSpinBox更新范围取决于其他spinbox的值

时间:2011-04-25 11:28:31

标签: python pyqt pyqt4

我正在使用pyqt4首次开发GUI;

我有一个spinbox,我希望它中允许的值范围取决于另一个spinbox的值。例如,第一个spinbox中允许的最大值应该等于第二个spinbox的值。

我认为使用valueChanged()信号来调用类似的方法是可能的:

def function
    max = spinbox2.value()
    spinbox1.setMaximum(max)

但是没有用,有人知道怎么做吗?

谢谢

1 个答案:

答案 0 :(得分:2)

您没有在代码中显示spinbox2的'valueChanged'信号与function之间的连接。你正在建立这种联系吗?您为function提供的代码似乎也不完整。

您可以尝试这样的事情:

spinbbox2.valueChanged.connect(handler)
# Or this which works for Python 3.5
spinbbox2.valueChanged[int].connect(handler)

# The function handler called is called whenever
# value in spinbox2 is changed and parameter to
# handler is the new value of spinbox2
def handler(value):
    spinbox1.setMaximum(value)