Results 1 to 18 of 18

Thread: How to find out the type of the clicked item..

Hybrid View

Previous Post Previous Post   Next Post Next Post
  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 How to find out the type of the clicked item..

    Hi..

    I have mutiple items drawn on the canvas... they are either line or rectangles..
    I want to find out which exact item i have clicked on... ie i item on which i have clicked is line or rect.. how do i find that out...

    Thanking you,
    Kapil

  2. #2
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to find out the type of the clicked item..

    The following functions will help you with your task

    Q3CanvasItemList collisions ( const QPoint & p ) const (in Q3Canvas)
    virtual int rtti () const (in Q3CanvasItem)

  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: How to find out the type of the clicked item..

    Quote Originally Posted by munna
    The following functions will help you with your task

    Q3CanvasItemList collisions ( const QPoint & p ) const (in Q3Canvas)
    virtual int rtti () const (in Q3CanvasItem)
    Hi..

    Thanks..

    Yaa true.. they will help me in finding out the item i have clicked on...

    But i have 10 Line objects and 20 rectangle object.. Now of them whcih Line object has been clicked or which of the Rectangle object has been clicked is my question...

    ie is it the 3rd line or the 5th.. or it is the 3rd rect or the 8th... How to retrieve this specific info.. do i have to write my own functions that would reduce to find out the information..

    Kapil

  4. #4
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to find out the type of the clicked item..

    In that case you can maintain a list of items for comparision. You can have a list of all the lines, a list of all the rectangles and so on... Once you get the item that was selected or clicked, first find out if it was a line or rectangle.. and then compare the selected item with the appropriate list items to find out which line or rectangle was selected.

    Hope you understood!!

  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: How to find out the type of the clicked item..

    Quote Originally Posted by munna
    In that case you can maintain a list of items for comparision. You can have a list of all the lines, a list of all the rectangles and so on... Once you get the item that was selected or clicked, first find out if it was a line or rectangle.. and then compare the selected item with the appropriate list items to find out which line or rectangle was selected.

    Hope you understood!!
    Thanks a lot...

    About my understanding i would just let you know what i deduced ->

    I would have to maintain a list wherein i would have to keep the entire information of lines and rectangles and their exact locations... and whereever i have clicked, i would have to find the position and compare it with the line or rect location..

    Is it what u wanted to say..

    what are the other ways in which comparisons can be made ????

  6. #6
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to find out the type of the clicked item..

    Quote Originally Posted by kapil
    I would have to maintain a list wherein i would have to keep the entire information of lines and rectangles and their exact locations...
    you just have to maintain a list of pointers of your items. Their locations are not needed.

  7. #7
    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: How to find out the type of the clicked item..

    Quote Originally Posted by munna
    you just have to maintain a list of pointers of your items. Their locations are not needed.
    Hi...

    Yaa i have done that... i have the list of all the line and rect pointers with me...
    But how will i know that the item i have clicked on is the "nth" line or "nth" rectangle....

    can u give me some example or few lines of code that explains the thing...

    it would be really very helpful for me...

    Thanking you...

    Kapil
    Last edited by Kapil; 30th March 2006 at 12:22.

  8. #8
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to find out the type of the clicked item..

    ok here it is

    Qt Code:
    1. QList<Q3CanvasItem *> lineList;
    2. QList<Q3CanvasItem *> rectList;
    3.  
    4. Q3CanvasItem *l = new Q3CanvasLine(yourCanvas);
    5. lineList.append(l);
    6.  
    7. //Similarly Build your rectangle list;
    To copy to clipboard, switch view to plain text mode 

    Now to find which line was clicked

    Qt Code:
    1. Q3CanvasItem* item;
    2. // Find an item, e.g. with Q3CanvasItem::collisions().
    3. ...
    4. if (item->rtti() == Rtti_Line) {
    5. for(int i = 0; i< lineList.size(); ++i){
    6. if(lineList.at(i) == item){
    7. //Here you know that you have clicked the line which in the list is at i th location
    8. }
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 

    Hope this helps

  9. The following user says thank you to munna for this useful post:

    Kapil (30th March 2006)

  10. #9
    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: How to find out the type of the clicked item..

    Hi...

    yaa i got the basic idea..
    what i have done is this now:

    First the creation of the Line List:
    Qt Code:
    1. QList<Q3CanvasItem *> lineList;
    2.  
    3. Q3CanvasItem **l;
    4. l = new Q3CanvasLine*[numLines]; //numLines is the number of lines on Canvas.
    5. for(i=0;i<numLines;i++)
    6. {
    7. l[i] = new Q3CanvasLine(yourCanvas);
    8. l[i] = canvasLine[i];
    9. lineList.append(l[i]);
    10. }
    11.  
    12. Same for the Rectangle;
    To copy to clipboard, switch view to plain text mode 

    Is it correct...

  11. #10
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to find out the type of the clicked item..

    In your code you are actually having two list. One in the form of QList and the other as array. This is not required. One is enough to perform the task.

    Cheers

  12. #11
    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: How to find out the type of the clicked item..

    Quote Originally Posted by munna
    In your code you are actually having two list. One in the form of QList and the other as array. This is not required. One is enough to perform the task.

    Cheers
    which means this:

    Qt Code:
    1. QList<Q3CanvasItem *> lineList;
    2.  
    3. Q3CanvasItem *l = new Q3CanvasLine(yourCanvas);
    4. l[i] = canvasLine[i];
    5. lineList.append(l[i]);
    To copy to clipboard, switch view to plain text mode 

    is this what you were saying

    Also the line lineList.at(i) == m_itemLine is giving error...

    Its giving the comparison error as m_itemList is not a pointer object whereas the other one is... creating m_itemLine pointer creates problem with the collision statement as it return a non-pointer object value...
    Last edited by Kapil; 30th March 2006 at 14:34.

Similar Threads

  1. Compile 4.4.0
    By LordQt in forum Installation and Deployment
    Replies: 18
    Last Post: 29th May 2008, 13:43
  2. problems installing Qt opensource with msvc2008 support
    By odin1985 in forum Installation and Deployment
    Replies: 6
    Last Post: 24th May 2008, 09:06
  3. How to know wich item is clicked QTreeWidget
    By ^NyAw^ in forum Qt Programming
    Replies: 13
    Last Post: 6th November 2007, 23:47
  4. dummy question(Error)
    By Masih in forum Qt Programming
    Replies: 12
    Last Post: 19th July 2007, 23:38
  5. Getting item from QTableView when clicked on
    By steg90 in forum Qt Programming
    Replies: 3
    Last Post: 23rd May 2007, 11:58

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.