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:
{
QTime mousePressEventTime
=QTime::currentTime();
// gets the time of press event
scene()->setActiveWindow(this);
windowSizePropertyAnimationZoomIn()->start(QAbstractAnimation::KeepWhenStopped);
// QGraphicsProxyWidget::mousePressEvent(event);
emit zoomTransition();
}
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();
}
To copy to clipboard, switch view to plain text mode
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:
{
mousePressEventTime()->start();
scene()->setActiveWindow(this);
windowSizePropertyAnimationZoomIn()->start(QAbstractAnimation::KeepWhenStopped);
// QGraphicsProxyWidget::mousePressEvent(event);
emit zoomTransition();
}
{
scene()->setActiveWindow(this);
if(mousePressEventTime()->elapsed()<=static_cast<int>(PRESS_DURATION))
{
// handle code
}
else
{ windowSizePropertyAnimationZoomOut()->start(QAbstractAnimation::KeepWhenStopped);
} // if
void WidgetProxy::mousePressEvent (QGraphicsSceneMouseEvent * event)
{
mousePressEventTime()->start();
scene()->setActiveWindow(this);
windowSizePropertyAnimationZoomIn()->start(QAbstractAnimation::KeepWhenStopped);
// QGraphicsProxyWidget::mousePressEvent(event);
emit zoomTransition();
}
void WidgetProxy::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
scene()->setActiveWindow(this);
if(mousePressEventTime()->elapsed()<=static_cast<int>(PRESS_DURATION))
{
// handle code
}
else
{ windowSizePropertyAnimationZoomOut()->start(QAbstractAnimation::KeepWhenStopped);
} // if
To copy to clipboard, switch view to plain text mode
Sincerely,
Marko
Bookmarks