Results 1 to 1 of 1

Thread: QGraphicsProxyWidget::mousePressEvent time related question [SOLVED]

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default QGraphicsProxyWidget::mousePressEvent time related question [SOLVED]

    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:
    Qt Code:
    1. void CWidgetProxy::mousePressEvent (QGraphicsSceneMouseEvent * event)
    2. {
    3. QTime mousePressEventTime=QTime::currentTime(); // gets the time of press event
    4.  
    5. scene()->setActiveWindow(this);
    6.  
    7. windowSizePropertyAnimationZoomIn()->start(QAbstractAnimation::KeepWhenStopped);
    8. // QGraphicsProxyWidget::mousePressEvent(event);
    9. emit zoomTransition();
    10. }
    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:
    Qt Code:
    1. void WidgetProxy::mousePressEvent (QGraphicsSceneMouseEvent * event)
    2. {
    3. mousePressEventTime()->start();
    4.  
    5. scene()->setActiveWindow(this);
    6.  
    7. windowSizePropertyAnimationZoomIn()->start(QAbstractAnimation::KeepWhenStopped);
    8. // QGraphicsProxyWidget::mousePressEvent(event);
    9. emit zoomTransition();
    10. }
    11.  
    12. void WidgetProxy::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
    13. {
    14. scene()->setActiveWindow(this);
    15.  
    16. if(mousePressEventTime()->elapsed()<=static_cast<int>(PRESS_DURATION))
    17. {
    18. // handle code
    19. }
    20. else
    21. { windowSizePropertyAnimationZoomOut()->start(QAbstractAnimation::KeepWhenStopped);
    22. } // if
    To copy to clipboard, switch view to plain text mode 
    Sincerely,
    Marko
    Last edited by MarkoSan; 6th December 2009 at 07:01.
    Qt 5.3 Opensource & Creator 3.1.2

Similar Threads

  1. Pointer Question related to QLineEdit
    By ChrisReath in forum Qt Programming
    Replies: 1
    Last Post: 23rd May 2008, 15:13
  2. directory related question
    By abrou in forum Newbie
    Replies: 1
    Last Post: 18th April 2008, 19:34
  3. Just in time compiler question
    By mickey in forum General Discussion
    Replies: 2
    Last Post: 16th July 2007, 23:08
  4. Question related to Q3DataTable
    By mitesh_modi in forum Qt Programming
    Replies: 0
    Last Post: 29th November 2006, 08:49

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
  •  
Qt is a trademark of The Qt Company.