Results 1 to 6 of 6

Thread: QGraphicsItem paint problem

Threaded View

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

    Default QGraphicsItem paint problem

    Hello,

    I have following files

    architem.h
    =========

    Qt Code:
    1. #ifndef ARCITEM_H
    2. #define ARCITEM_H
    3.  
    4. #include <QtWidgets>
    5.  
    6. class ArcItem : public QGraphicsItem
    7. {
    8. public:
    9. ArcItem(QGraphicsItem *parent=0);
    10. ~ArcItem();
    11.  
    12. QRectF boundingRect() const;
    13. void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
    14. void setRect(QRectF rct);
    15.  
    16. protected:
    17. QVariant itemChange(GraphicsItemChange change, const QVariant &value);
    18.  
    19. private:
    20. QRectF arcRect;
    21. int startAngle;
    22. int spanAngle;
    23.  
    24. };
    25.  
    26. #endif // ARCITEM_H
    To copy to clipboard, switch view to plain text mode 

    arcitem.cpp
    =========

    Qt Code:
    1. #include "arcitem.h"
    2.  
    3. ArcItem::ArcItem(QGraphicsItem *parent): QGraphicsItem(parent),
    4. arcRect(0,0,100,100),
    5. startAngle(1*16),
    6. spanAngle(200*16)
    7. {
    8. setFlags(ItemIsSelectable|ItemIsMovable|ItemSendsGeometryChanges);
    9. setData(0,"ArcItem");
    10. }
    11.  
    12. ArcItem::~ArcItem()
    13. {
    14.  
    15. }
    16.  
    17. QVariant ArcItem::itemChange(GraphicsItemChange change, const QVariant &value)
    18. {
    19. return QGraphicsItem::itemChange(change, value);
    20. }
    21.  
    22.  
    23.  
    24. QRectF ArcItem::boundingRect() const
    25. {
    26. return arcRect;
    27. }
    28.  
    29. void ArcItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
    30. {
    31. Q_UNUSED(option)
    32. Q_UNUSED(widget)
    33. painter->save();
    34. painter->drawArc(arcRect,startAngle,spanAngle);
    35. painter->restore();
    36. }
    37.  
    38. void ArcItem::setRect(QRectF rct)
    39. {
    40. arcRect = rct;
    41. update(rct);
    42. }
    To copy to clipboard, switch view to plain text mode 


    When I am resizing this item using handles, it show uncleared lines on scene as the picture attached.
    Actually, boundingrect is set from outside of this class by calling setRect custom method in this class.
    Although item gets resized, it behaves as per attachment.
    Any help on this?


    Thanks

    Manish
    Attached Images Attached Images

Similar Threads

  1. Custom QGraphicsItem paint function problem
    By andzero in forum Newbie
    Replies: 1
    Last Post: 12th October 2011, 18:35
  2. Help on QGraphicsItem::paint please
    By lni in forum Qt Programming
    Replies: 1
    Last Post: 18th July 2011, 08:11
  3. QGraphicsItem paint not triggered
    By roband915 in forum Qt Programming
    Replies: 9
    Last Post: 31st March 2011, 10:06
  4. Qgraphicsitem parent/child paint problem.
    By repka3 in forum Qt Programming
    Replies: 1
    Last Post: 24th July 2009, 22:03
  5. Paint QGraphicsItem problem
    By dreamer in forum Qt Programming
    Replies: 3
    Last Post: 23rd June 2008, 18:18

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.