Accessing QT constants in PyQt...


So you get an event and you want to be able to check something like whether a button press was done with the right mouse... fear not, you can access all the same constants that you are accustom to in C++ QT:

void MyClass::mousePressEvent(QMouseEvent * e)
{
  if (e->button() == Qt::RightButton)
  {
    printf("Something...")
  }
}

In Python you can do the same:

def mousePressEvent(self, event):
  if event.button() == Qt.RightButton:
    print "Something..."

Just remember that you need to have the PyQt import to have access to the constants:

from PyQt4.QtCore import *

Reply