Issue
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 and the mouse button held pressed, moving the mouse 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
Solution
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.
Answered By - Pavel Strakhov
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.