Results 1 to 1 of 1

Thread: Custom QGraphicsItem Resize

  1. #1
    Join Date
    Jun 2010
    Posts
    97
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Custom QGraphicsItem Resize

    Hello,

    I have following custom shape

    Qt Code:
    1. #include "basicshape.h"
    2.  
    3. BasicShape::BasicShape(QGraphicsItem *parent) :
    4. QGraphicsItem(parent),brect(100,100,200,50)
    5. {
    6. setFlags(ItemIsSelectable|ItemIsMovable|ItemSendsGeometryChanges);
    7. }
    8.  
    9.  
    10. QRectF BasicShape::boundingRect() const
    11. {
    12. return brect;
    13. }
    14.  
    15. void BasicShape::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
    16. {
    17. Q_UNUSED(option)
    18. Q_UNUSED(widget)
    19. painter->save();
    20. painter->drawRect(brect);
    21. painter->restore();
    22. }
    23.  
    24. void BasicShape::setRect(QRectF rct)
    25. {
    26. prepareGeometryChange();
    27. brect = rct;
    28. update();
    29. }
    To copy to clipboard, switch view to plain text mode 

    And this object is passed in other object which attaches handles as shown in attachment to this shape and also makes this shape a parent item to that handle item. Now when I move handles by pressing it resizes correctly. But when I move bottom center point above top center or right center point toward left than left center then shape distorts. This is because moving handle position becomes negative. And due to this negative point it is unable to update bounding rect properly.

    Is there any remedy where this issue will be addressed. This becomes worst when shape is instead of rectangle it is line item.


    Manish
    Attached Images Attached Images

Similar Threads

  1. Resize QGraphicsItem when window resizes
    By guidupas in forum Qt Programming
    Replies: 5
    Last Post: 24th May 2014, 17:32
  2. Replies: 0
    Last Post: 1st February 2010, 11:00
  3. QGraphicsItem Resize Problem
    By c_srikanth1984 in forum Qt Programming
    Replies: 3
    Last Post: 16th May 2009, 11:05
  4. resize a QGraphicsItem
    By dreamer in forum Qt Programming
    Replies: 1
    Last Post: 29th April 2008, 09:58
  5. Resize Border for QGraphicsItem
    By william.dias in forum Qt Programming
    Replies: 2
    Last Post: 8th February 2008, 09:19

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.