2014-11-23 136 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