PDA

View Full Version : How to delay a Signal?



trusch
25th June 2009, 14:31
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

Lykurg
25th June 2009, 14:51
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.

trusch
25th June 2009, 15:09
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.

Lykurg
25th June 2009, 15:48
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.

aekilic
25th June 2009, 15:59
what you could do is using QTimer like



QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(setT()));
timer->start(1000);

void setT()
{
xxxx->blockSignals(true);
}

Lykurg
25th June 2009, 16:17
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...

/// local timer t.
XX::XX()
{
t.setSingleShot(true);
connect(&t, SIGNAL(timeout()), this, SLOT(timerslot()));
}

XX::timerslot()
{
// if you want do so something right here, if not, you could
// direct emit the signal in the connect statement.
emit mouseFor3SecondsOverWidget();
}

XX::enterEvent()
{
t.start(3000);
}


XX::enterLeave()
{
t.stop();
}

trusch
26th June 2009, 06:18
Thanks a lot!