Is there any way by which I can detect if QDial
(with wrapped property set to true) was rotated clockwise or anticlockwise?
Asked
Active
Viewed 1,038 times
1 Answers
5
Let 0 the minimum and 100 the maximum of your wrapped QDial
. If the difference between two consecutive value changes is positive then you have an anti-clockwise rotation, if not you have a clockwise rotation (you have to adjust it to your actual values)
You should subclass QDial
and use the sliderMoved
signal :
This signal is emitted when sliderDown is true and the slider moves. This usually happens when the user is dragging the slider. The value is the new slider position.
This signal is emitted even when tracking is turned off.
Connect this signal to a slot that calculates if the rotation was clockwise or anti-clockwise
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
}
Now you can add a function that returns the direction
property of your subclass.

pnezis
- 12,023
- 2
- 38
- 38