PDA

View Full Version : Handling longpress.



Niamita
7th June 2011, 13:13
Hi
I want to create longpress of a painted shape, how it should done?
Waiting for your reply.

Santosh Reddy
7th June 2011, 14:25
What is a painted shape, I mean what is the Qt type used for it

If your painted shape if of type QWidget then, it can be this way



void MyWidget::mousePressEvent(QMouseEvent* event)
{
long_press_timer = startTimer(4000); // 4 second Longpress
}

void MyWidget::mouseReleaseEvent(QMouseEvent* event)
{
long_press_timer = 0;
}

void MyWidget::timerEvent(QTimerEvent* event)
{
if(long_press_timer == event->timerId())
{
// processes long press
}
long_press_timer = 0;
killTimer(vent->timerId());
}

If your shape is of type QGraphicsObject, it is similar, implement these


void MyGraphicsObject::mousePressEvent(QGraphicsSceneMo useEvent* event);
void MyGraphicsObject::mouseReleaseEvent(QGraphicsScene MouseEvent* event);
void MyGraphicsObject::timerEvent(QTimerEvent* event);