Results 1 to 3 of 3

Thread: QGraphicsView::itemAt() always returns zero

  1. #1
    Join Date
    Jul 2012
    Posts
    244
    Thanks
    27
    Thanked 15 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QGraphicsView::itemAt() always returns zero

    So i created a few MyItem instances and addItem()ed then to my custom QGraphicsView. This works perfectly, and the widgets show up just fine.
    However, the scene()->itemAt(...) functions returns always zero, when given the coordinates obtained from a QMouseEvent.


    Qt Code:
    1. class MyItem: public QGraphicsProxyWidget
    2. {
    3. MyItem() {
    4. setWidget(new SomeWidget());
    5. }
    6. //...
    7. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void MyQGraphicsView::mousePressEvent( QMouseEvent *event )
    2. {
    3. QGraphicsItem* itm = scene()->itemAt(event->pos()); //nope
    4. itm = scene()->itemAt(event->pos(), transform()); //nope
    5. }
    To copy to clipboard, switch view to plain text mode 



    Now, i am still struggling with understanding all the transformation stuff :/, but to my understanding, nothing of that sort should be necessary here? Unfortunately, this seems to be a rarely used function, and i cant seem to find any proper examples.


    Do i have to apply some magic to the coordinates before passing them to the function? What else could be 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: QGraphicsView::itemAt() always returns zero

    The coordinates are in viewport's coordinate space. You need to map that to the scene first.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jul 2012
    Posts
    244
    Thanks
    27
    Thanked 15 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsView::itemAt() always returns zero

    i really need to do more reading on all this. thanks.

Similar Threads

  1. ItemAt and ScenePos
    By jano_alex_es in forum Newbie
    Replies: 3
    Last Post: 26th October 2009, 15:48
  2. Qt: TableWidget’s ItemAt() acting weirdly
    By emredog in forum Qt Programming
    Replies: 2
    Last Post: 19th October 2009, 08:50
  3. Querying object type using itemAt
    By ajb in forum Qt Programming
    Replies: 1
    Last Post: 24th June 2009, 17:35
  4. itemAt - does not select rect
    By gjshannon in forum Qt Programming
    Replies: 3
    Last Post: 14th March 2009, 22:51
  5. QTreeWidget itemAt
    By maartenS in forum Newbie
    Replies: 4
    Last Post: 17th September 2008, 20:19

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.