QSlider值更改信号 [英] QSlider Value Changed Signal

查看:870
本文介绍了QSlider值更改信号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用QSlider(v4.6)输入以及向用户提供反馈。对于反馈我将调用setValue方法。我试图找到一个信号,只有当用户修改的值才会触发。当用户更改该值以及调用setValue时,valueChanged信号触发。 sliderMoved仅在用户拖动滑块(而不是使用键盘)时触发。我检查了API文档,似乎找不到任何东西。我缺少什么?这似乎是常见的东西。如果没有其他信号,你会如何推荐我模拟这个功能?我应该在调用setValue之前设置一个标志,在每次调用setValue ...时断开并重新连接信号?

I'm using a QSlider (v4.6) for input as well as to provide feedback to the user. For the feedback I will be calling the setValue method. I'm trying to find a signal that will fire only if the user modified the value. The valueChanged signal fires when the user changed the value as well as when I call setValue. sliderMoved only fires when the user drags the slider (not when using the keyboard). I checked the API docs and can't seem to find anything. Am I missing something? This seems something that would be common. If there is no other signal, how would you recommend that I simulate this functionality? Should I set a flag before calling setValue, disconnect and reconnect the signal every time I call setValue...?

推荐答案

,我检查了API,也找不到一个信号,只有当用户修改的值才会触发。您提出的解决方法可能是唯一的选择,请记住,您不必断开/连接所有信号,只需使用 QObject :: blockSignals 方法:

Good question, I checked the API and also couldn't find a signal that would be triggered only if value was modified by user. The workaround you proposed may be the only option, just keep in mind that you don't have to disconnect / connect all signals, just use QObject::blockSignals method:

slider->blockSignals(true);
slider->setValue(x);
slider->blockSignals(false);

希望有帮助。

这篇关于QSlider值更改信号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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