2014-11-23 28 views
0

您可以使用通常的标志位掩码来设置dropActions。从the docs,我们有以下可能的放置动作:Qt DropActions:什么是ActionMask?

Action     Value  Result 
Qt::CopyAction   0x1 (1) Copy the data to the target. 
Qt::MoveAction   0x2 (2) Move the data from the source to the target. 
Qt::LinkAction   0x4 (4) Create a link from the source to the target. 
Qt::ActionMask   0xff (255) [none given in docs] 
Qt::IgnoreAction  0x0 (0) Ignore the action (do nothing with the data). 

我被ActionMask措施混淆。我还没有找到任何关于它的讨论(例如,herehere),甚至没有任何关于它的例子(比如Nullege)。它的价值是,所以任何时候你按位or它与任何其他dropActions你只会以ActionMask再次结束。

那么,什么是ActionMask?何时使用?它在哪里记录?

编辑:

正如接受的答案指出,有一个的dropAction我离开了枚举,而这可能是关键:

TargetMoveAction 0x8002 (32770 in dec, 1000000000000010 in bin) 

回答

1

一般而言,面膜用于包含或排除其他值的某些位的值,使用按位运算。

DropAction enum的定义,包括另一标志:

Qt::TargetMoveAction 0x8002 

其是掩模的范围之外。所以面膜可以用来筛选出这样的值,比如:

>>> from PySide.QtCore import Qt 
>>> a = Qt.CopyAction | Qt.TargetMoveAction 
>>> int(a) 
32771 
>>> int(a & Qt.ActionMask) 
3 

,反之亦然:

>>> int(a & ~Qt.ActionMask) 
32768 

至于为什么它可能用于:Qt4的使用它的精确其中一个位于其源代码中,即QtDropActionToDndOperation函数gui/kernel/qmotifdnd_x11.cpp。做你会...

+0

我应该包括在我的枚举dropaction ...它似乎关键:我想知道如果这些被添加到qt在一起使用你的建议。 – neuronet 2014-11-23 19:45:26

+0

有趣的是'TargetMoveAction'以'10'结尾,所以它隐含地包含'MoveAction'。 – neuronet 2014-11-23 19:58:59

+0

@neuronet。 Qt在它的几个枚举中提供了掩码,最常见的用法似乎是提供一种易于维护的方法来包含所有可能的标志,而不必事先知道它们的实际内容。鉴于'TargetMoveAction'在所有平台上的使用方式都不相同,它似乎有意义的是它具有超出蒙版范围的值。 – ekhumoro 2014-11-23 20:35:21