2011-11-21 90 views

回答

5

设0为包装QDial的最小值和最大值。如果两个连续值变化之间的差值为正值,则表示逆时针旋转,如果不是,则表示顺时针旋转(必须将其调整为实际值)

您应该子类QDial并使用sliderMoved信号:

当sliderDown为真且滑块移动时,发出此信号。 这通常发生在用户拖动滑块时。值 是新的滑块位置。

即使关闭跟踪,也会发射此信号。

这个信号连接到计算如果旋转是顺时针或逆时针

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 
} 

现在,您可以添加返回子类的direction属性功能的插槽。

相关问题