Re: Is there way to change item's parent?



On 12 May 2011 15:53, Nikita Zlobin <nick87720z gmail com> wrote:
> I have two groups, one is nested to another. And i need to add new
> group to topmost and nest previously created child to new. I have
> implemented dragging, which is performed for now by affecting "x" and
> "y" properties via g_object_set ().
>
> Each group has nested rectangle. Events are received by topmost group,
> so i can drag entier group, clicking on any element (one time i tried
> to drag children rectangles - works fine).
>
> 1. If i just add item to new parent, i get two images of item. Old image
> seems to just i mirage - it doesn't react for mouse events, but new -
> reacts.
> 2. If i first remove item from old parent - it seems, it
> is destroyed; because on subsequential attempt to add item to new
> parent i get segmentation fault.
> 3. Also i tried to remove item from old parent after it is adopted by
> new parent, but in this case it doesn't react for events (not dragged
> by mouse). And if i try to drag rectangle, nested to topmost group
> (appart another rectangle, nested to group, whose parent was changed),
> i again get segmentation fault.

You need to ref the item before removing it, something like this:

  g_object_ref (item);
  goo_canvas_item_remove (item);
  goo_canvas_item_add_child (new_parent, item, -1);
  g_object_unref (item);

The "Reparent" page of the demo does this. See demo/demo-features.c

Damon


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]