Results 1 to 4 of 4

Thread: Emitting a series of signals as long as a QPushButton is pressed

  1. #1
    Join Date
    Feb 2009
    Location
    Germany
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default 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

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Emitting a series of signals as long as a QPushButton is pressed

    Quote Originally Posted by qbird View Post
    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.

  3. #3
    Join Date
    Nov 2009
    Posts
    129
    Thanks
    4
    Thanked 29 Times in 29 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default 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?

  4. The following user says thank you to Coises for this useful post:

    qbird (17th November 2009)

  5. #4
    Join Date
    Feb 2009
    Location
    Germany
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Smile 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

    Great forum, indeed !

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.