将 QComboBox 或 QSpinBox 设置为不允许的值
我正在维护一个应用程序,它试图帮助用户让他的参数一起工作,因为存在许多相互依赖关系。
现在变量 Y 有一个默认值 x。当用户更改其他某个变量 Z 时,Y 可能会出现一个大于 x 的新最小值。这被设置为旋转框的最小值。现在旋转框不能再显示当前值,而是显示最小值。我希望用户能够看到他以前的价值。是否有一些我在 Qt 中看不到的设置来实现这样的目标?
同样的问题也适用于 QComboBox。
I am maintaining an application which tries to help the user get his parameters to work together, as there are many interdependencies.
Now there is a default value of x for a variable Y. When the user changes some other variable Z, there might be a new minimum value for Y which is greater than x. This is set as a minimum for the spinbox. Now the spinbox can not display the current value anymore, but rather displays the minimum. I would like the user to be able to see his old value. Is there some setting I don't see in Qt to achieve something like this?
Same question goes for QComboBox.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
作为一种方法,您可以创建新类,继承自 Qt 标准 QSpinBox(或者在第二种情况下继承自 QComboBox)并向其中添加您自己的逻辑:可以显示低于最小值的值,但是当有人想要显式更改输入小部件中的值时,您将检查边界。
As one approach you may create new class, inherited from Qt standart QSpinBox(or in second case from QComboBox) and add your own logic to them: posibility to show value below the minimum, but when someone want explicitly change value in your input widgets, you will check for bounds.
另一种方法是将每个小部件连接到函数,该函数将检查其他值是否正确(如果不正确,则会更正它们):)
Another approach is to connect each widget to function that will check if others values are correct (and if not will correct them) :)