Results 1 to 5 of 5

Thread: unified the cursor and item coordinate

  1. #1
    Join Date
    Oct 2009
    Location
    China
    Posts
    20
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    15

    Question unified the cursor and item coordinate

    Qt Code:
    1. int i = 1;
    2. QPoint posi = QCursor::pos();
    3. QPointF postemp = (QPointF)posi;
    4. foreach(coordinator cor1, m_pageListback1)
    5. {
    6. if((cor1.x <= postemp.x()) && (cor1.y <= postemp.y()) && ((cor1.x+192) >= postemp.x()) && ((cor1.y+256) >= postemp.y()))
    7. {
    8. pagenum = i; //index of the item in the QVector
    9. break;
    10. }
    11. i++;
    12. }
    To copy to clipboard, switch view to plain text mode 
    m_pageListback1 is a QVector Container ,they are items' top-left coordinate(these coordinates are the result of QGraphicsItem::mapToScene ).every item's width = 192,height = 256.I want to judge ,whether the cursor is in the scope of the item.
    but it is not accurate.Is there some way to unify the coordinate.
    Thanks!!!!!

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 370 Times in 336 Posts

    Default Re: unified the cursor and item coordinate

    you can get item's rect and test if a point contains in the rect using QRect::contains.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Oct 2009
    Location
    China
    Posts
    20
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    15

    Default Re: unified the cursor and item coordinate

    Thanks!
    Do you mean:
    Qt Code:
    1. int i = 1;
    2. QPoint posi = QCursor::pos();
    3. QPointF postemp = (QPointF)posi;
    4.  
    5. foreach(QGraphicsItem* page, m_pageList)
    6. {
    7. if(page->contains(postemp))
    8. {
    9. pagenum = i;
    10. break;
    11. }
    12. i++;
    13. }
    To copy to clipboard, switch view to plain text mode 
    I try this,but it doesn't work.

  4. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 370 Times in 336 Posts

    Default Re: unified the cursor and item coordinate

    try this
    Qt Code:
    1. ...
    2. if(page->boundingRect().contains(postemp))
    3. ...
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  5. #5
    Join Date
    Oct 2009
    Location
    China
    Posts
    20
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    15

    Default Re: unified the cursor and item coordinate

    Thank you!
    Sorry,I didn't say it clear.
    1.the page item , I haven't reimplemented boundingRect();
    2.the page items, I have reduced these items by 20%,then relocated them,let them in a sequence.

Tags for this Thread

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.