Results 1 to 2 of 2

Thread: Move QGraphicsScene by mouse

  1. #1
    Join Date
    Jul 2010
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Question Move QGraphicsScene by mouse

    HI!

    I want to move a scene with mouse (left mouse button with CTRL). I use this code:

    Qt Code:
    1. void GraphicsView::mousePressEvent (QMouseEvent *event)
    2. {
    3. if (event->button () == Qt::LeftButton && event->modifiers ().testFlag (Qt::ControlModifier))
    4. {
    5. setDragMode (QGraphicsView::ScrollHandDrag);
    6. setInteractive (false);
    7.  
    8. _originX = event->x ();
    9. _originY = event->y ();
    10. }
    11. else
    12. {
    13. QGraphicsView::mousePressEvent (event);
    14. }
    15. }
    16.  
    17. void GraphicsView::mouseMoveEvent (QMouseEvent *event)
    18. {
    19. if (event->buttons () & Qt::LeftButton && event->modifiers ().testFlag (Qt::ControlModifier))
    20. {
    21. QPointF oldp = mapToScene (_originX, _originY);
    22. QPointF newp = mapToScene (event->pos ());
    23. QPointF translation = newp - oldp;
    24.  
    25. translate (translation.x (), translation.y ());
    26.  
    27. _originX = event->x ();
    28. _originY = event->y ();
    29. return;
    30. }
    31.  
    32. QGraphicsView::mouseMoveEvent (event);
    33. }
    34.  
    35. void GraphicsView::mouseReleaseEvent (QMouseEvent *event)
    36. {
    37. if (event->button () == Qt::LeftButton && event->modifiers ().testFlag (Qt::ControlModifier))
    38. {
    39. setDragMode (QGraphicsView::NoDrag);
    40. setInteractive (true);
    41. }
    42. else
    43. {
    44. QGraphicsView::mouseReleaseEvent (event);
    45. }
    46. }
    To copy to clipboard, switch view to plain text mode 

    And this code is not work.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Move QGraphicsScene by mouse

    Is the scene larger than the view?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 11
    Last Post: 19th September 2013, 23:00
  2. Replies: 3
    Last Post: 22nd February 2013, 20:56
  3. Problem with QGraphicsScene mouse move event
    By Nesbit in forum Qt Programming
    Replies: 2
    Last Post: 22nd April 2012, 19:12
  4. How can I move a QWidget across a QGraphicsScene
    By Maduka in forum Qt Programming
    Replies: 0
    Last Post: 8th November 2011, 13:40
  5. Move Rectangle on mouse Move
    By vermarajeev in forum Qt Programming
    Replies: 24
    Last Post: 14th May 2007, 06:34

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.