Results 1 to 6 of 6

Thread: Higlighting wrong item

  1. #1
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Higlighting wrong item

    Hi...

    I am facing a problem while highlighting the Q3Canvas items...
    I have drawn few CanvasLines which criss cross each other...
    now i have activated the Mouse events on it.. when clicked on the any item it returns me the point...
    with the point using the collisions function of Canvas am able to extract all the items... but when i compare it with my list of Canvas Line, it returns me the first line drawn always no matter which one i click...

    Note: When i removed the criss-crossing of them and each set of lines were independent and not overlapping, i was returned the exact item on which i had clicked... The problem comes when the lines cut eachother i.e. there is atleast one intersection point between them..

    what can be the solution to this problem....
    i am finding it hard to come up with a solution...

    Thank you.

    with regards,
    Kapil
    All you have to decide is what to do with the time that is given to you

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Higlighting wrong item

    Did you actually care to read the docs?
    Q3CanvasItemList Q3Canvas::collisions ( const QPoint & p ) const
    Returns a list of canvas items that collide with the point p. The list is ordered by z coordinates, from highest z coordinate (front-most item) to lowest z coordinate (rear-most item).

  3. #3
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Higlighting wrong item

    hi..

    yaa i had read it and used it with the same concept but the problem was there... i would show u those few lines where i had done so...
    Qt Code:
    1. Q3CanvasItemList l = m_pCanvas->collisions(item);
    2. selCanItem = l;
    3. for (Q3CanvasItemList::Iterator it= selCanItem.begin(); it!= selCanItem.end(); ++it)
    4. {
    5. if ( (*it)->rtti() == 7 )
    6. {
    7. for(i=0;i<42;i++)
    8. {
    9. if((i<GlobalOutYLineList.size()) && ((*it)->collidesWith(GlobalOutYLineList.at(i))))
    10. {
    11. QMessageBox::information(this, tr("CGUITileType"),tr("GlobalOutYLineList Line %1 Mouse Event Handled ").arg(i));
    12. m_pCLineGlobalOutY[i]->setPen(QPen(Qt::red));
    13. startPoint = m_pCLineGlobalOutY[i]->startPoint();
    14. endPoint = m_pCLineGlobalOutY[i]->endPoint();
    15. m_pCLineGlobalOutY[i]->setPoints(startPoint.x(),startPoint.y(),endPoint.x(),endPoint.y());
    16. m_pCLineGlobalOutY[i]->show();
    17. break;
    18. }
    19. else if((i<V1_DirectInputLineList.size())&& ((*it)->collidesWith(V1_DirectInputLineList.at(i))))
    20. {
    21. QMessageBox::information(this, tr("CGUITileType"),tr("V1_DirectInputLineList Line %1 Mouse Event Handled ").arg(i));
    22. m_pV1_CLineDirectInput[i]->setPen(QPen(Qt::red));
    23. startPoint = m_pV1_CLineDirectInput[i]->startPoint();
    24. endPoint = m_pV1_CLineDirectInput[i]->endPoint();
    25. m_pV1_CLineDirectInput[i]->setPoints(startPoint.x(),startPoint.y(),endPoint.x(),endPoint.y());
    26. m_pV1_CLineDirectInput[i]->show();
    27. break;
    28. }
    To copy to clipboard, switch view to plain text mode 

    Now the problem is no matter which canvas item i click, it enters the first 'if' and highlights the 0th item...

    Kapil
    All you have to decide is what to do with the time that is given to you

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Higlighting wrong item

    What are the bounding boxes for these two lines?

  5. #5
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Higlighting wrong item

    hi...

    i have not used boundingRect() function for the lines anywhere to find the bounding boxes..
    i have created QList and stored the line items in it and then compared it with the Q3CanvasItemList with the collideswith(0 function...

    How can knowing the bounding box help ???
    I would also try it out .....

    Kapil
    All you have to decide is what to do with the time that is given to you

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Higlighting wrong item

    Quote Originally Posted by Kapil
    i have not used boundingRect() function for the lines anywhere to find the bounding boxes..
    Nevermind, Q3CanvasLines::areaPoints() will be used to detect collision for lines.

    Quote Originally Posted by Kapil
    Now the problem is no matter which canvas item i click, it enters the first 'if' and highlights the 0th item...
    And what item it should highlight? Maybe you should skip the "else" keyword?

    I don't see much sense in this part:
    Qt Code:
    1. startPoint = m_pCLineGlobalOutY[i]->startPoint();
    2. endPoint = m_pCLineGlobalOutY[i]->endPoint();
    3. m_pCLineGlobalOutY[i]->setPoints(startPoint.x(),startPoint.y(),endPoint.x(),endPoint.y());
    To copy to clipboard, switch view to plain text mode 
    Haven't you messed the variable names somewhere?

Similar Threads

  1. ListWidget positions item
    By talex in forum Qt Programming
    Replies: 3
    Last Post: 21st October 2008, 15:16
  2. View, Scene, Item and thread??
    By dungsivn in forum Qt Programming
    Replies: 5
    Last Post: 20th August 2008, 19:21
  3. Item in a DLL not getting events
    By Benne Gesserit in forum Qt Programming
    Replies: 11
    Last Post: 16th August 2008, 22:30
  4. Item Delegate Painting
    By stevey in forum Qt Programming
    Replies: 3
    Last Post: 9th May 2008, 07:37
  5. Replies: 1
    Last Post: 19th April 2007, 22:23

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.