3
votes

I'm building a GUI with Python and Qt. The standard widgets are quite useful and work out of the box. However, I have some ideas about mouse gestures. More precisely, a button or label or text, that, after being clicked ant the mouse held pressed, moving the mouse around around has special effects.

What is necessary to add mouse support for the following events

  • mouse clicked over widget A while it was visible
  • mouse moved to x, y (at real time)
  • mouse released

to an arbitrary widget?


Right now I am trying to do this by class A, which inherits QAbstractItemView and owns a QWidget. However, nothing works AND

NotImplementedError: QAbstractItemView.verticalOffset() is abstract and must be overridden

1
QAbstractItemView is, well, abstract You have to implement all pure virtual methods to instantiate it..trompa

1 Answers

2
votes

QAbstractItemView is not helpful for your task.

You can install event filter on an arbitrary widget using installEventFilter. Your filter class must be inherited from QObject. The documentation contains some useful examples. See QObject::installEventFilter. If you want to install filter on all widgets at once, you can install it for QApplication instance.

Another option is to subclass QWidget (or any other QWidget-derived class) and reimplement its mousePressEvent, mouseMoveEvent and mouseReleaseEvent virtual functions.