It is not the same as ==
. It is bitwise AND operator. What the expression does is that it takes the return value from event->buttons()
and bitwise AND's it with the value represented by Qt::LeftButton
. If the resulting value is non-zero the block is being executed.
In essence, it checks if the button specified by Qt::LeftButton
is held down.
The reason why the bitwise AND
operator is used here is something called a bitmask. What it means is that the return value of event->buttons()
is just a value which has it's bits represent different kinds of states. What is done with the &-operator here is that it checks if certain bits(denoted by Qt::LeftButton
) are being set(1) or unset(0) in the value returned by event->buttons()
. The return value is zero if no tested bit is set, and non-zero, if at least one of the tested bits is set.
More details of how bitwise operations work can be found here: Wikipedia article about Bitwise operations
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…