I don't know if I understand correctly, but since by default you can press the QPushButton only with left mouse button, try:
connect(btn, SIGNAL(pressed()), obj, SLOT(startWork()));
connect(btn, SIGNAL(released()), obj, SLOT(stopWork()));
connect(btn, SIGNAL(pressed()), obj, SLOT(startWork()));
connect(btn, SIGNAL(released()), obj, SLOT(stopWork()));
To copy to clipboard, switch view to plain text mode
in order to protect yourself from the scenario:
- user clicked left, but not yet released
- mouse pointer left the widgets boundaries while user is holding the btn down
you can reimplement button's leaveEvent and stop the work there too.
I don't really remember if the released() wouldn't be called anyway if mouse pointer is outside the button, but that's quite easy to test.
Bookmarks