PyQt QSpinBox根据其他SpinBox的值更新范围
我第一次使用pyqt4来开发图形界面;
我有一个数字选择框(spinbox),我希望这个选择框里允许的数值范围能根据另一个数字选择框的值来变化。比如,第一个选择框的最大值应该等于第二个选择框的值。
我想这可能可以通过一个叫做valueChanged()的信号来实现,调用一个类似于下面的函数:
def function
max = spinbox2.value()
spinbox1.setMaximum(max)
但是这样并没有成功,有人知道该怎么做吗?
谢谢
1 个回答
4
你没有展示你是怎么把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)