Q滑块步进?
我想指定 QSlider 可以滑动的步骤,就像使用 setSingleStep
可以为 QSpinBox 滑动一样。我尝试使用QAbstractSlider的setSingleStep,但这似乎没有效果。
有什么想法吗?
I'd like to specify the steps that a QSlider can slide, like it is possible for the QSpinBox by using setSingleStep
. I tried to use setSingleStep of QAbstractSlider, but this seems to have no effect.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试设置 tickInterval
编辑
抱歉对于tickInterval,没有充分考虑它,但是我有这个工作代码,它使用 setSingleStep 执行您想要的操作
Try setting the tickInterval
EDIT
Sorry for the tickInterval, didn't quite thinked about it, however i have this working code and it does what you want using setSingleStep
我扩展了 QSlider 类来限制用户,以便他们无法跟踪步骤之间的滑块。
SetInterval
方法相当于组合setTickInterval
和setSingleStep
方法,但也会阻止滑块位于刻度值之间。该类还允许使用浮点值作为滑块限制或间隔,并允许设置和读取滑块上所选点的索引。
I extended the QSlider class to limit the user so that they cannot track the slider between the steps.
The
SetInterval
method is equivalent to combining thesetTickInterval
andsetSingleStep
methods, but also stops the slider being positioned between tick values.The class also allows the use of float values as slider limits or intervals and allows the index of the point selected on the slider to be set and read.
我的解决方案是使用信号 sliderMoved 并纠正位置。下面的示例将滑块移动到值 50 或 100
My solution is using signal sliderMoved and correct the position. The below example moves slider to value 50 or 100
setSingleStep() 现在仍然无法在 PyQt5 中的滑块上工作,
所以我尝试这样做来达到相同的效果,
我刚刚学了几个月的 python
如果有错误请纠正
setSingleStep() still don't work on slider in PyQt5 now
so I tried this to make the same effect
I just learned python for several months
Please correct it if there is a mistake