查找QDial是顺时针还是逆时针旋转

时间:2011-11-21 10:10:58

标签: qt qt4 qdial

有什么方法可以检测QDial(包裹的属性设置为true)是顺时针还是逆时针旋转?

1 个答案:

答案 0 :(得分:5)

将0包裹QDial的最小值和最大值设为100。如果两个连续值变化之间的差异为正,那么您将进行逆时针旋转,如果不是顺时针旋转(您必须将其调整为实际值)

您应该继承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
}

现在您可以添加一个返回子类的direction属性的函数。

相关问题