简体   繁体   English

QDial 子类如何停止从最小值移动到最大值?

[英]How Subclass QDial to Stop Moving from Min to Max?

I would like to subclass QDial, because when you're at min value, you can change value to max easily (by going down).我想继承 QDial,因为当您处于最小值时,您可以轻松地将值更改为最大值(通过下降)。 Same problem from max to min.从最大到最小同样的问题。

In order to do that, I know I have to subclass QDial.为了做到这一点,我知道我必须继承 QDial。 But I don't know where to start.但我不知道从哪里开始。

I may provide some guidance to you... let's try.我可能会为您提供一些指导……让我们尝试一下。

First of all you should start with QDial , not QAbstractSlider , because the target methods you should reimplement are首先你应该从QDial开始,而不是QAbstractSlider ,因为你应该重新实现的目标方法是

  • virtual void mouseMoveEvent(QMouseEvent *e)
  • virtual void mousePressEvent(QMouseEvent *e)
  • virtual void mouseReleaseEvent(QMouseEvent *e)

which handle mouse actions like the names state.它处理像名称状态这样的鼠标操作。 Looking at the source you can see, that the methods of question simply try to map the cursor position to a valid dial position.查看来源,您可以看到,问题方法只是尝试将光标位置映射到有效的拨号位置。 Here the 'jump' happens, which you want to disable (I tried several control keys (page up/down, arrow up/down, mouse wheel and mouse click/drag) and only by clicking you may skip an undefined amount of values.).这里发生了“跳转”,您想禁用它(我尝试了几个控制键(向上/向下翻页、向上/向下箭头、鼠标滚轮和鼠标单击/拖动),只有通过单击,您才能跳过未定义数量的值。 )。 Additionally you may want to set pageStep to a value you application supports.此外,您可能希望将pageStep设置为您的应用程序支持的值。


As a solution I may propose that you take the result of the valueFromPoint method and decrement or increment (if the value is lesser or bigger) the current value instead of setting it to the result.作为一种解决方案,我可能会建议您采用valueFromPoint方法的结果并减少或增加(如果该值较小或较大)当前值,而不是将其设置为结果。 This should disable jumps.这应该禁用跳转。

Qt 5.6.0 Qt 5.6.0

I came across this question looking for information about how to change some of the dial properties.我遇到了这个问题,寻找有关如何更改某些拨号属性的信息。 You can stop the slider on the dial moving from min to max "quickly" (jumping across) by using the setWrapping(bool) slot.您可以使用setWrapping(bool)插槽来停止表盘上的滑块“快速”(跳过)从最小值移动到最大值。

myNewDial = new QDial(whateverYourQWidgetIs);
myNewDial->setWrapping(true);

This will give you the full 360 degree range of motion of the slider.这将为您提供滑块的完整 360 度运动范围。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM