keshav2010
30th July 2018, 02:00
Hello,
My application is based on the graphics view framework and so I'm trying to draw some images ( as loaded by user) and allow user to drag them around the scene
so basically I made a class "AnimatableItem" that inherits from QGraphicsPixmapItem
and this item has flag set to make it movable.
I've overrided AnimatableItem::paint() method as follow
//override
void AnimatableItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
painter->setPen(QColor(200,100,50));
painter->drawPixmap(boundingRect().x(), boundingRect().y(), boundingRect().width(), boundingRect().height(), this->pixmap());
painter->setBrush(QBrush(QColor(0,0,0)));
painter->drawRect(this->pos().x(), this->pos().y(), this->boundingRect().width(), this->boundingRect().height());
}
as you see, im drawing a pixmap which apparently seems to be at desired position
however the 2nd rectangle (black in color) which represents item position ( actual ) is always ahead of boundingRect position and keeps getting farther away as i move more toward
+x axis and +y axis , how do i make sure item's position and boundingRect() position is same ?
My application is based on the graphics view framework and so I'm trying to draw some images ( as loaded by user) and allow user to drag them around the scene
so basically I made a class "AnimatableItem" that inherits from QGraphicsPixmapItem
and this item has flag set to make it movable.
I've overrided AnimatableItem::paint() method as follow
//override
void AnimatableItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
painter->setPen(QColor(200,100,50));
painter->drawPixmap(boundingRect().x(), boundingRect().y(), boundingRect().width(), boundingRect().height(), this->pixmap());
painter->setBrush(QBrush(QColor(0,0,0)));
painter->drawRect(this->pos().x(), this->pos().y(), this->boundingRect().width(), this->boundingRect().height());
}
as you see, im drawing a pixmap which apparently seems to be at desired position
however the 2nd rectangle (black in color) which represents item position ( actual ) is always ahead of boundingRect position and keeps getting farther away as i move more toward
+x axis and +y axis , how do i make sure item's position and boundingRect() position is same ?