PDA

View Full Version : QGraphicsItem selection trouble



zgulser
12th August 2009, 10:33
Hi,

I have a QGraphicsItem object called SearchAreaItem which has a shape just like ellipse. This ellipse is formed by short lines which are also QGraphicsItem called LineItem. When I hover the mouse over one of those lines, the line becomes red( because of the way I implemented). However, the problem is; I want the whole shape to be red - not only the line I'm currently on.

How can I get over this problem?

Thanks in advance

wagmare
12th August 2009, 11:38
set a common flag in header

update() the paint() function when hover enter event occurs with a flag set to 1
and update() the paint() function when hover leave event occurs with flag set to 0

in paint()
if(flag == 1)
setBrush(rect(), color)

zgulser
12th August 2009, 12:57
Hi again,

you mean should I implement these in the SearchAreaItem(the parent). Moreover, if it is, I should take care of each line in the paint method ?

Plus, are you sure there is a need for hoverEnterEvent... since it seems paint() of SearchAreaItem can handle it.

wagmare
12th August 2009, 13:05
i mean
in the graphicsItem::paint() function of SearchAreaItem ...

are u not painting your SearchAreaItem ..? if so u got the whole control of line ..

zgulser
12th August 2009, 13:11
yes, I do not paint in the SearchAreaItem. that's the problematic case already. But I want to control the not the lines but the whole shape formed by these lines.

wysota
12th August 2009, 15:16
So access the rest of the lines and mark them to be highlighted. You surely have pointers to those objects somewhere so that shouldn't be a problem.

zgulser
13th August 2009, 10:18
I solved the problem. Thanks for your help.

But, I've come with a new one. I create SearchAreaItem as an ItemGroup and put the LineItems into it. What I want to achieve is to make the SearchAreaItem act as the only item when I perform movement operation. But it confused about the shape() function. In my LineItem class I implement the shape() for more precise mouse operations. In addition to that reimplementation of shape(), I also reimplement it in SearchAreaItem. So what's the deal here? Only one proper shape will be sufficient? Is there any extra work needed for grouping items out of adding the group to the scene and adding the items to that group?

Thanks in advance!

wysota
13th August 2009, 11:15
No, there is nothing more required apart from creating the group. Unfortunately your description is not clear enough to understand what your problem is. Providing a piece of code would be helpful.

zgulser
13th August 2009, 13:33
I would wish to send a bit but I'm not allowed:/.

Anyway, I'm trying my best to explain it once.

I have many LineItems which are created and form an ellipse inside another item group called SearchAreaItem. Futhermore, each LineItem has a shape() function for more efficiency(I assume you've seen the reason already). Now, what I really want to do is treat this SearchAreaItem as the composite item. Don't want to deal with LineItem's created inside it when the mouse hover over click operations take place. That's why I designed the SeachAreaItem as an item group.

Now I want to ask, what the main usage of setHandlesChildEvents method?

and, although I didn't implement the itemChange() method, I'm now able to drag-drop my SearchAreaItem( the ellipse) by only setting movable flag. Isn't it a bit odd?

wagmare
13th August 2009, 14:11
Now I want to ask, what the main usage of setHandlesChildEvents method?
itemGroup->setHandlesChildEvents (false ); will make all the members in the group independent ...

without setting this .. the focus will be on whole .. mouse click is common everywhere to the group members ..

zgulser
13th August 2009, 16:33
... what about the shape() function?