PDA

View Full Version : QGraphicsProxyWidget::mousePressEvent time related question [SOLVED]



MarkoSan
6th December 2009, 04:33
Hi to all!

I have a nasty following problem:
I have several QProxyWidgets on QGraphicsScene and once the user presses mouse button on one of them, mousePressEvent is called. Is mousePressEvent called only once for a mouse button press or it iterates as long mouse button is pressed down? How do I measure a time (secs or msec) of how long the button is held down?

Ok, the event is called once (until the button is released), that is clear now. Here is my code:
void CWidgetProxy::mousePressEvent (QGraphicsSceneMouseEvent * event)
{
QTime mousePressEventTime=QTime::currentTime(); // gets the time of press event

scene()->setActiveWindow(this);

windowSizePropertyAnimationZoomIn()->start(QAbstractAnimation::KeepWhenStopped);
// QGraphicsProxyWidget::mousePressEvent(event);
emit zoomTransition();
}No how, do I get some kind of stopwatch to measure difference between mousePressEventTime and end time?

I found a solution. First, at mousePressEvent i start QTime object and at mouseReleaseEvent I call elapsed() method from previous QTime object:

void WidgetProxy::mousePressEvent (QGraphicsSceneMouseEvent * event)
{
mousePressEventTime()->start();

scene()->setActiveWindow(this);

windowSizePropertyAnimationZoomIn()->start(QAbstractAnimation::KeepWhenStopped);
// QGraphicsProxyWidget::mousePressEvent(event);
emit zoomTransition();
}

void WidgetProxy::mouseReleaseEvent(QGraphicsSceneMouse Event *event)
{
scene()->setActiveWindow(this);

if(mousePressEventTime()->elapsed()<=static_cast<int>(PRESS_DURATION))
{
// handle code
}
else
{ windowSizePropertyAnimationZoomOut()->start(QAbstractAnimation::KeepWhenStopped);
} // ifSincerely,
Marko