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
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
The following functions will help you with your task
Q3CanvasItemList collisions ( const QPoint & p ) const (in Q3Canvas)
virtual int rtti () const (in Q3CanvasItem)
Hi..Originally Posted by munna
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
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...Originally Posted by munna
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 ????
you just have to maintain a list of pointers of your items. Their locations are not needed.Originally Posted by kapil
Hi...Originally Posted by munna
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.
ok here it is
Qt Code:
QList<Q3CanvasItem *> lineList; QList<Q3CanvasItem *> rectList; Q3CanvasItem *l = new Q3CanvasLine(yourCanvas); lineList.append(l); //Similarly Build your rectangle list;To copy to clipboard, switch view to plain text mode
Now to find which line was clicked
Qt Code:
Q3CanvasItem* item; // Find an item, e.g. with Q3CanvasItem::collisions(). ... if (item->rtti() == Rtti_Line) { for(int i = 0; i< lineList.size(); ++i){ if(lineList.at(i) == item){ //Here you know that you have clicked the line which in the list is at i th location } } }To copy to clipboard, switch view to plain text mode
Hope this helps
Kapil (30th March 2006)
Hi...
yaa i got the basic idea..
what i have done is this now:
First the creation of the Line List:
Qt Code:
QList<Q3CanvasItem *> lineList; Q3CanvasItem **l; l = new Q3CanvasLine*[numLines]; //numLines is the number of lines on Canvas. for(i=0;i<numLines;i++) { l[i] = new Q3CanvasLine(yourCanvas); l[i] = canvasLine[i]; lineList.append(l[i]); } Same for the Rectangle;To copy to clipboard, switch view to plain text mode
Is it correct...
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:Originally Posted by munna
Qt Code:
QList<Q3CanvasItem *> lineList; Q3CanvasItem *l = new Q3CanvasLine(yourCanvas); l[i] = canvasLine[i]; 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.
Bookmarks