PyQt4, class:mouseButtons用法

>>> from PyQt4 import * 
>>> bt = QtCore.Qt.MouseButtons() 
>>> bt 
<PyQt4.QtCore.MouseButtons object at 0x013FE848> 
>>> new = bt.__or__(Qt.LeftButton) 
>>> new 
<PyQt4.QtCore.MouseButtons object at 0x013FE810> 
>>> new.__int__() 
1 
>>> bt.__int__() 
0 
>>> new = bt.__or__(Qt.RightButton) 
>>> new.__int__() 
2 
>>>  

用MouseButtons的__int__()方法即可将类换成一个int型,然后判断有无Qt.RightButton:

if(new.__int__() & Qt.RightButton):

    #Right Button Clicked, Do Something Here....

    pass

你可能感兴趣的:(Class,pyqt4,MouseButtons)