设0为最小值,100为最大值QDial.如果两个连续值变化之间的差值为正,那么你有一个逆时针旋转,如果不是顺时针旋转(你必须调整到你的实际值)
你应该子类化QDial并使用sliderMoved信号:
当sliderDown为true且滑块移动时,会发出此信号.这通常发生在用户拖动滑块时.该值是新的滑块位置.
即使关闭跟踪,也会发出此信号.
将此信号连接到槽,计算旋转是顺时针还是逆时针
connect(this, SIGNAL(sliderMoved(int)), this, SLOT(calculateRotationDirection(int)));
void calculateRotationDirection(int v)
{
int difference = previousValue - v;
// make sure we have not reached the start...
if (v == 0)
{
if (previousValue == 100)
direction = DIRECTION_CLOCKWISE;
else
direction = DIRECTION_ANTICLOCKWISE;
}
else if (v == 100)
{
if (previousValue == 0)
direction = DIRECTION_ANTICLOCKWISE;
else
direction = DIRECTION_CLOCKWISE;
}
else
{
if (difference > 0)
direction = DIRECTION_ANTICLOCKWISE; // a simple enum
else if (difference < 0)
direction = DIRECTION_CLOCKWISE;
}
previousValue = v; // store the previous value
}
Run Code Online (Sandbox Code Playgroud)
现在,您可以添加一个返回direction子类属性的函数.
| 归档时间: |
|
| 查看次数: |
826 次 |
| 最近记录: |