Results 1 to 3 of 3

Thread: mapToItem() question

  1. #1
    Join Date
    Apr 2008
    Location
    Ireland
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default mapToItem() question

    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:

    Qt Code:
    1. QPointF getRelativeOrigin(QGraphicsItem *myFirstItem, QGraphicsItem *mySecondItem)
    2. {
    3. QPointF *centrePoint;
    4. QPointF relativePoint;
    5.  
    6. centrePoint = new QPointF(0.0, 0.0);
    7. relativePoint = myFirstItem->mapToItem (mySecondItem, centrePoint);
    8. return relativePoint;
    9. }
    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?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: mapToItem() question

    The second argument is a const reference, not a pointer.

    Qt Code:
    1. QPointF result = first->mapToItem(second, QPointF(0.0,0.0));
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Apr 2008
    Location
    Ireland
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Thumbs up Re: mapToItem() question

    Thanks! That did the trick.

Similar Threads

  1. SQL Question
    By ^NyAw^ in forum Qt Programming
    Replies: 5
    Last Post: 8th April 2008, 19:36
  2. Exceptions / setjmp/longjmp question
    By Aceman2000 in forum Qt Programming
    Replies: 3
    Last Post: 13th March 2008, 17:14
  3. Replies: 1
    Last Post: 15th March 2007, 20:45
  4. Question regarding how to paint after zoom.
    By JonathanForQT4 in forum Qt Programming
    Replies: 2
    Last Post: 26th January 2007, 15:34

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.