monitor for declarativeitem resize

This commit is contained in:
Marco Martin 2011-03-19 18:36:29 +01:00
parent c216fe47b8
commit b958bf1480

View File

@ -39,11 +39,15 @@ public:
void setDeclarativeItem(QDeclarativeItem *item) void setDeclarativeItem(QDeclarativeItem *item)
{ {
if (m_declarativeItem) {
m_declarativeItem.data()->removeSceneEventFilter(this);
}
m_declarativeItem = item; m_declarativeItem = item;
static_cast<QGraphicsItem *>(item)->setParentItem(this); static_cast<QGraphicsItem *>(item)->setParentItem(this);
setMinimumWidth(item->implicitWidth()); setMinimumWidth(item->implicitWidth());
setMinimumHeight(item->implicitHeight()); setMinimumHeight(item->implicitHeight());
resize(item->width(), item->height()); resize(item->width(), item->height());
item->installSceneEventFilter(this);
} }
QDeclarativeItem *declarativeItem() const QDeclarativeItem *declarativeItem() const
@ -60,6 +64,15 @@ protected:
} }
} }
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event)
{
if (event->type() == QEvent::GraphicsSceneResize) {
resize(watched->boundingRect().size());
}
return QGraphicsWidget::sceneEventFilter(watched, event);
}
private: private:
QWeakPointer<QDeclarativeItem> m_declarativeItem; QWeakPointer<QDeclarativeItem> m_declarativeItem;
}; };