Results 1 to 4 of 4

Thread: The function QGraphicsScene::itemAt problem

  1. #1
    Join Date
    Dec 2009
    Posts
    15
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Windows

    Default The function QGraphicsScene::itemAt problem

    Hi all,

    I've created a custom class (named as Flow) inherited by QGraphicsItem. It's composing of an arrow and curve. I've used the function itemAt to determine which item has selected when QGraphicsScene::mousePressEvent is called. But it does not always return correct item. Otherwise I've written the folllowing function for manual detection. It's working correctly. But I want to learn why sometimes QGraphicsScene can not detect item selected by pressing mouse? Is there a more sensible method than manual point control?

    Qt Code:
    1. int getMatchedFlow(QPointF pos)
    2. {
    3. int fID = -1;
    4. QList<Flow*> mFlowList = mGroupStore.keys();
    5. QList<Flow*>::iterator i;
    6. Flow *pFlow;
    7.  
    8. for (i = mFlowList.begin(); i != mFlowList.end(); ++i)
    9. {
    10. pFlow = (Flow*)*i;
    11. if (pFlow->checkPointSet(pos))
    12. {
    13. fID = pFlow->getID();
    14. break;
    15. }
    16. }
    17.  
    18. return fID;
    19. }
    20.  
    21. bool Flow::checkPointSet(QPointF point)
    22. {
    23. bool rc = false;
    24.  
    25. if (mBoundingPath.contains(point))
    26. {
    27. rc = true;
    28. }
    29.  
    30. return rc;
    31. }
    To copy to clipboard, switch view to plain text mode 

    Thanks a lot for your helps,
    Last edited by yaseminyilmaz; 2nd April 2012 at 11:12.

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

    Default Re: The function QGraphicsScene::itemAt problem

    How did you implement boundingRect() and shape() for your item?
    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
    Dec 2009
    Posts
    15
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: The function QGraphicsScene::itemAt problem

    I've implemented as following. I've noticed that sometimes getMatchedFlow has not detect when I click the arrow in addition to the function QGraphicsScene::itemAt. What can the problem be?

    Qt Code:
    1. QPainterPath Flow::shape() const
    2. {
    3. return mBoundingPath;
    4. }
    5.  
    6. QRectF Flow::boundingRect() const
    7. {
    8. return mRectF;
    9. }
    10.  
    11. void Flow::updateBoundingRect()
    12. {
    13. prepareGeometryChange();
    14.  
    15. mBoundingPath = QPainterPath();
    16.  
    17. addArrow(); // it adds arrow polygon to mBoundingPath
    18. addCurve(); // it adds curve path to mBoundingPath
    19.  
    20. mRectF = mBoundingPath.boundingRect();
    21.  
    22. updateScene();
    23. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: The function QGraphicsScene::itemAt problem

    Do you have overlapping items? If so, do you have different zorder set for them?
    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.


Similar Threads

  1. Replies: 5
    Last Post: 31st July 2014, 00:52
  2. Move function for widget won't works in QGraphicsScene
    By alizadeh91 in forum Qt Programming
    Replies: 0
    Last Post: 3rd March 2012, 10:43
  3. Replies: 1
    Last Post: 16th April 2011, 09:23
  4. QTreeWidget itemAt
    By maartenS in forum Newbie
    Replies: 4
    Last Post: 17th September 2008, 20:19
  5. Order of elemetns with QGraphicsScene::itemAt
    By Morea in forum Qt Programming
    Replies: 2
    Last Post: 20th December 2006, 22:00

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
  •  
Qt is a trademark of The Qt Company.