Hello,
I have following files
architem.h
=========
#ifndef ARCITEM_H
#define ARCITEM_H
#include <QtWidgets>
{
public:
~ArcItem();
protected:
private:
int startAngle;
int spanAngle;
};
#endif // ARCITEM_H
#ifndef ARCITEM_H
#define ARCITEM_H
#include <QtWidgets>
class ArcItem : public QGraphicsItem
{
public:
ArcItem(QGraphicsItem *parent=0);
~ArcItem();
QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
void setRect(QRectF rct);
protected:
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
private:
QPainterPath path;
QRectF arcRect;
int startAngle;
int spanAngle;
};
#endif // ARCITEM_H
To copy to clipboard, switch view to plain text mode
arcitem.cpp
=========
#include "arcitem.h"
arcRect(0,0,100,100),
startAngle(1*16),
spanAngle(200*16)
{
setFlags(ItemIsSelectable|ItemIsMovable|ItemSendsGeometryChanges);
setData(0,"ArcItem");
}
ArcItem::~ArcItem()
{
}
{
}
QRectF ArcItem
::boundingRect() const {
return arcRect;
}
{
Q_UNUSED(option)
Q_UNUSED(widget)
painter->save();
painter->drawArc(arcRect,startAngle,spanAngle);
painter->restore();
}
void ArcItem
::setRect(QRectF rct
) {
arcRect = rct;
update(rct);
}
#include "arcitem.h"
ArcItem::ArcItem(QGraphicsItem *parent): QGraphicsItem(parent),
arcRect(0,0,100,100),
startAngle(1*16),
spanAngle(200*16)
{
setFlags(ItemIsSelectable|ItemIsMovable|ItemSendsGeometryChanges);
setData(0,"ArcItem");
}
ArcItem::~ArcItem()
{
}
QVariant ArcItem::itemChange(GraphicsItemChange change, const QVariant &value)
{
return QGraphicsItem::itemChange(change, value);
}
QRectF ArcItem::boundingRect() const
{
return arcRect;
}
void ArcItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option)
Q_UNUSED(widget)
painter->save();
painter->drawArc(arcRect,startAngle,spanAngle);
painter->restore();
}
void ArcItem::setRect(QRectF rct)
{
arcRect = rct;
update(rct);
}
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
Bookmarks