Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python or pyqt - checking mouse button clicked state

I need to check if a mouse button is clicked or released. I'm using pyqt - any way to check the mouse button release state in qt or directly in python?

I know of pygame module but would prefer not to have to install it.

like image 497
mickeyMouse Avatar asked May 19 '11 16:05

mickeyMouse


1 Answers

Check you doc at PyQt4/doc/html/qt.html#MouseButton-enum

Constant    Value
Qt.NoButton 0x00000000
Qt.LeftButton   0x00000001
Qt.RightButton  0x00000002
Qt.MidButton    0x00000004
Qt.MiddleButton MidButton
Qt.XButton1 0x00000008
Qt.XButton2 0x00000010

A simple example:

>>> from PyQt4 import QtCore, QtGui
>>> app=QtGui.QApplication([])
>>> mouse_state=app.mouseButtons()
>>> mouse_state==QtCore.Qt.NoButton
True
>>> int(mouse_state)
0
like image 93
Kabie Avatar answered Oct 16 '22 10:10

Kabie