Well so far found out that when I set the bounding rectangle, it does change it to whatever I set it. I create my path Item drawing a path on the scene and then creating the item giving that path. So when I set it a new bounding rectangle I want the same exact path to be redrawn within the new bounding rectangle that I gave it. So far no matter what size of rectangle I set it to the item disappears, but I noticed that the outline of the bounding rectangle is there, just that the actual path item is not redrawn in the new bounding rectangle.
I keep the QPainterPath that I give it as a member variable so I am doing this:
{
painter->setBrush(brush);
painter->setOpacity(0.4);
m_path.setFillRule(Qt::WindingFill);
painter->drawPath(m_path);
}
QRectF PathItem
::boundingRect() const {
return m_rect;
}
{
return m_path;
}
{
m_path = _path;
m_rect = path().boundingRect();
}
void PathItem
::setBoundingRect(QRectF rect
) {
prepareGeometryChange();
m_rect = rect;
update(m_rect);
}
void PathItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
QBrush brush(QColor(200, 200, 200));
painter->setBrush(brush);
painter->setOpacity(0.4);
m_path.setFillRule(Qt::WindingFill);
painter->drawPath(m_path);
}
QRectF PathItem::boundingRect() const
{
return m_rect;
}
QPainterPath PathItem::shape() const
{
return m_path;
}
void PathItem::setPath(const QPainterPath &_path)
{
QGraphicsPathItem::setPath(_path);
m_path = _path;
m_rect = path().boundingRect();
}
void PathItem::setBoundingRect(QRectF rect)
{
prepareGeometryChange();
m_rect = rect;
update(m_rect);
}
To copy to clipboard, switch view to plain text mode
Where am I going wrong?
Bookmarks