Question

I have 3 events defined as follows:

void mouseMoveEvent(QMouseEvent *eventMove);
void mousePressEvent(QMouseEvent *eventPress);
void mouseReleaseEvent(QMouseEvent *releaseEvent);

Now, let's say I want to do something when the mouse is clicked and moved until the mouse is released. e.g. Give an output ! until the conditions described upper are true.

EDIT: I have tried to set a global variable let's say bool a and make it true in mousePressEvent(...), false in mouseReleaseEvent(...), but when in mouseMoveEvent(...) the a is always true, even when button is released.

Était-ce utile?

La solution

This is exactly the same code as in:

Tracking mouse coordinates in Qt

But without the setMouseTracking(true). With setMouseTracking(false) (the default) the void mouseMoveEvent(QMouseEvent *event) method is only called, when a mousebutton is pressed.

No mousePressEvent(QMouseEvent *eventPress) or mouseReleaseEvent(QMouseEvent *releaseEvent) needed for your requirements.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top