Hi,
I'm trying to get the position of the origin point of a graphics item (myFirstItem) relative to another graphics item (mySecondItem) using Qt 4. From reading the documentation, it looks like mapToItem() should do this for me, specifically:
QPointF QGraphicsItem::mapToItem ( const QGraphicsItem * item, const QPointF & point ) const
I attempted to implement this as follows:
{
centrePoint
= new QPointF(0.0,
0.0);
relativePoint = myFirstItem->mapToItem (mySecondItem, centrePoint);
return relativePoint;
}
QPointF getRelativeOrigin(QGraphicsItem *myFirstItem, QGraphicsItem *mySecondItem)
{
QPointF *centrePoint;
QPointF relativePoint;
centrePoint = new QPointF(0.0, 0.0);
relativePoint = myFirstItem->mapToItem (mySecondItem, centrePoint);
return relativePoint;
}
To copy to clipboard, switch view to plain text mode
It seems to assume a different interface to the method mapToItem() then I expect as the following errors are returned when I build:
demo.cpp: In member function ‘QPointF demo::getRelativeOrigin(QGraphicsItem*, QGraphicsItem*)’:
demo.cpp:146: error: invalid conversion from ‘QPointF*’ to ‘int’
demo.cpp:146: error: initializing argument 1 of ‘QPolygonF::QPolygonF(int)’
demo.cpp:146: error: no match for ‘operator=’ in ‘relativePoint = QGraphicsItem::mapToItem(const QGraphicsItem*, const QPolygonF&) const(((const QGraphicsItem*)mySecondItem), ((const QPolygonF&)(& QPolygonF(((int)centrePoint)))))’
/usr/local/Trolltech/Qt-4.3.4/include/QtCore/qpoint.h:190: note: candidates are: QPointF& QPointF:perator=(const QPointF&)
Can anyone suggest where I am going wrong?
Bookmarks