PyQt QSpinBox 更新范围取决于其他 spinbox 的值 [英] PyQt QSpinBox update range depending on the value of other spinbox

查看:49
本文介绍了PyQt QSpinBox 更新范围取决于其他 spinbox 的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是第一次使用pyqt4开发GUI;

i am using pyqt4 to develop a GUI for the first time;

我有一个旋转框,我希望它允许的值范围取决于另一个旋转框的值.例如,第一个旋转框允许的最大值应该等于第二个旋转框的值.

I have a spinbox, and I would like the range of values allowed in it to be dependant on the value another spinbox. for example, the maximum value allowed in the first spinbox should be equal to the value of the second spinbox.

我认为这可能使用 valueChanged() 信号来调用类似于以下内容的方法:

I thought this may be possible using a valueChanged() signal to call a method that is something like:

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

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

but that didnt work, does anyone know how to do this?

谢谢

推荐答案

您没有显示您的代码,其中您在 spinbox2 的 'valueChanged' 信号与 function 之间建立了联系.你在做那种联系吗?此外,您为 function 提供的代码似乎不完整.

You have not shown your code where you make the connection between the 'valueChanged' signal of spinbox2 with the function. Are you making that connection ?. Also the code you have given for function seems to be incomplete.

你可以试试这样的:

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)

这篇关于PyQt QSpinBox 更新范围取决于其他 spinbox 的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆