Results 1 to 2 of 2

Thread: Restrict Boundary for QGraphicsPolygonItem

  1. #1
    Join Date
    Apr 2011
    Posts
    7
    Qt products
    Qt Jambi
    Platforms
    Windows

    Default Restrict Boundary for QGraphicsPolygonItem

    Hey guys,

    I havea a QGraphicsPolygonItem (Just a simple rectangle) that I can drag around in my QGraphicsScene.

    I can select the shape and drag it around. However if it is dragged too far to the edge of the window, it gets clipped and goes off screen.

    Have a look at the API but couldn't find how I can restrict the area the polygon can move around.

    Any ideas?

    Thanks

    Sean

  2. #2
    Join Date
    Apr 2011
    Posts
    7
    Qt products
    Qt Jambi
    Platforms
    Windows

    Default Re: Restrict Boundary for QGraphicsPolygonItem

    Found the solution to the problem.

    Qt Code:
    1. public void mouseMoveEvent(QGraphicsSceneMouseEvent event)
    2. {
    3. super.mouseMoveEvent(event);
    4.  
    5. if (movingBlock != null)
    6. {
    7. if(movingBlock.pos().x() <= 0.0)
    8. {
    9. movingBlock.setPos(0.0, movingBlock.y());
    10. }
    11.  
    12. if(movingBlock.pos().x() >= this.sceneRect().width())
    13. {
    14. movingBlock.setPos(this.sceneRect().width(), movingBlock.y());
    15. }
    16.  
    17. if(movingBlock.pos().y() <= 0)
    18. {
    19. movingBlock.setPos(movingBlock.x(), 0.0);
    20. }
    21.  
    22. if(movingBlock.pos().y() >= this.sceneRect().height())
    23. {
    24. movingBlock.setPos(movingBlock.x(), this.sceneRect().height());
    25. }
    26. }
    27. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QGraphicsRectItem vs QGraphicsPolygonItem
    By Doru in forum Qt Programming
    Replies: 0
    Last Post: 26th January 2011, 07:12
  2. QGraphicsPolygonItem with holes
    By natnan in forum Qt Programming
    Replies: 0
    Last Post: 2nd August 2010, 09:44
  3. I need help in QGraphicsPolygonItem
    By c_srikanth1984 in forum Qt Programming
    Replies: 0
    Last Post: 15th April 2009, 10:53
  4. QPaintEngine and QGraphicsPolygonItem
    By magland in forum Qt Programming
    Replies: 1
    Last Post: 19th August 2008, 16:03
  5. How to fix the boundary..??
    By deepusrp in forum Qt Programming
    Replies: 18
    Last Post: 17th May 2007, 04:41

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.