Results 1 to 7 of 7

Thread: How to delay a Signal?

  1. #1
    Join Date
    Jun 2009
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to delay a Signal?

    Hello,

    i have got a qtablewidget and i need a delayed hover effect. So I connected the table with my private slot (testslot):

    connect(tableWidget, SIGNAL(itemEntered(QTableWidgetItem*)), this, SLOT(testslot()));

    But this is without a delay. The mousepointer should stand 2 or 3 second over the table and then activate the signal.

    Thanks

  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: How to delay a Signal?

    I don't think there is such an option for delay in connect(), but you could simply use a QTimer with 2 seconds inside your slot.

  3. #3
    Join Date
    Jun 2009
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to delay a Signal?

    Thanks for answering,
    but this isn`t the right solution. I wont only a signal, if the mousepointer was 2-3 seconds over the table. With your idea, the signal is 2-3 seconds later on my slot, also if the mouse was only 1 second over the table.

  4. #4
    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: How to delay a Signal?

    Ok, I've misunderstand you. In your case you have to subclass and use QWidget::enterEvent() and QWidget::leaveEvent() (in conjunction with a QTimer) to prove if the cursor was 3 sec over the widget and then send your own signal.

  5. #5
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to delay a Signal?

    what you could do is using QTimer like

    Qt Code:
    1. QTimer *timer = new QTimer(this);
    2. connect(timer, SIGNAL(timeout()), this, SLOT(setT()));
    3. timer->start(1000);
    4.  
    5. void setT()
    6. {
    7. xxxx->blockSignals(true);
    8. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    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: How to delay a Signal?

    Since I hate my work right now and the van Damme movie, I currently watch, sucks, I am gentile and post the code I was thinking of...
    Qt Code:
    1. /// local timer t.
    2. XX::XX()
    3. {
    4. t.setSingleShot(true);
    5. connect(&t, SIGNAL(timeout()), this, SLOT(timerslot()));
    6. }
    7.  
    8. XX::timerslot()
    9. {
    10. // if you want do so something right here, if not, you could
    11. // direct emit the signal in the connect statement.
    12. emit mouseFor3SecondsOverWidget();
    13. }
    14.  
    15. XX::enterEvent()
    16. {
    17. t.start(3000);
    18. }
    19.  
    20.  
    21. XX::enterLeave()
    22. {
    23. t.stop();
    24. }
    To copy to clipboard, switch view to plain text mode 

  7. The following user says thank you to Lykurg for this useful post:

    trusch (26th June 2009)

  8. #7
    Join Date
    Jun 2009
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to delay a Signal?

    Thanks a lot!

Similar Threads

  1. pthread instead QThread
    By brevleq in forum Qt Programming
    Replies: 8
    Last Post: 23rd December 2008, 07:16
  2. Connection of custon signals/slots
    By brevleq in forum Qt Programming
    Replies: 2
    Last Post: 23rd December 2008, 07:04
  3. Possible signal mapper problem
    By MarkoSan in forum Qt Programming
    Replies: 13
    Last Post: 25th January 2008, 13:11
  4. Replies: 2
    Last Post: 17th May 2006, 21:01

Tags for this Thread

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.