1 Attachment(s)
QGraphicsItem paint problem
Hello,
I have following files
architem.h
=========
Code:
#ifndef ARCITEM_H
#define ARCITEM_H
#include <QtWidgets>
{
public:
~ArcItem();
protected:
private:
int startAngle;
int spanAngle;
};
#endif // ARCITEM_H
arcitem.cpp
=========
Code:
#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);
}
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
Re: QGraphicsItem paint problem
The new rect is not necessarly encompassing the old rect, right?
So calling update with just the new rect might leave area unupdated that was part of the previous rect.
Maybe call update with the union of the old and the new rect?
Cheers,
_
Re: QGraphicsItem paint problem
Thanks Anda.
I did that as well but still the problem persists. I have infact updated bigger viewport as well.
Re: QGraphicsItem paint problem
Is your item the only item showing that problem?
Have you tried without the ItemSendsGeometryChanges flag?
Cheers,
_
Re: QGraphicsItem paint problem
I don't see you calling prepareGeometryChange() after the bounding rect is changed.
Re: QGraphicsItem paint problem
Thanks Wysota.
Yes, prepareGeometryChange() has made the trick. Now it is working well and the problem is solved.
Thanks
Manish