Emitting a series of signals as long as a QPushButton is pressed
Hello,
I'd like to move a cursor in a function plot (Qwt-Plot) using two QPushButtons (left, right) to control the movement. The cursor shall move in one direction as long as the corresponding button is pressed.
If I connect the movement of the cursor to the SIGNAL(clicked()) of the QPushButtons, the cursor moves only one step forward each time the button is clicked. The user has to click the button many times to move the cursor over a longer distance. That's not what I want. I want the cursor to keep moving as long as the QPushButton is hold down. Somehow the QPushButton should keep firing signals as long as it is pressed.
Meanwhile I think I have to reimplement the QPushButton::mousePressEvent method. But as a novice to Qt I'm not sure whether this is the right way to go. Therefore any hints or suggestions are very welcome.
Thanks,
Dirk
Re: Emitting a series of signals as long as a QPushButton is pressed
Quote:
Originally Posted by
qbird
Meanwhile I think I have to reimplement the QPushButton::mousePressEvent method. But as a novice to Qt I'm not sure whether this is the right way to go. Therefore any hints or suggestions are very welcome.
I am sorry, but this is the way you have to take. But it isn't such difficult. Reimp mousePressEvent and start a timer firing signals, and stop with mouseReleaseEvent. Or better, only emit a "pressStart" signal and do the continuous moving inside the slot and stop it when you receive a "pressStop" signal. That would be better then firing signals all the time.
Re: Emitting a series of signals as long as a QPushButton is pressed
QPushButton derives from QAbstractButton; perhaps the auto-repeat property (QAbstractButton::autoRepeat-prop) will give you what you need?
Re: Emitting a series of signals as long as a QPushButton is pressed
Hi Lykurg and Coises, thanks for your quick replies.
Special thanks to you, Coises ... this was the hint I was looking for. Two simple lines of code
btnMoveCursorLeft->setAutoRepeat(true);
btnMoveCursorRight->setAutoRepeat(true);
have solved my problem :D
Great forum, indeed !