Re: [gtkmm] adding and removing widgets to/from fixed container



On Thu, 27 Mar 2003, Enrico Costanza wrote:

> I really have a lot of questions today.. :-)
>
> I am still working with Gtk::Fixed.
> I do need exact positioning; hopefully I should be able to handle everything I need with widgets and not need to draw anything.
> What I need is to display a number of multimedia elements (bitmaps, text and video clips) and having them appearing, disappearing and moving on screen. I want to use widgets (one widget for each multimedia element) because it seems an easy way, but I am not too sure now.

Still, the better (and easier) solution would be to use Gnome::Canvas.

> As mentioned in the subject, I want to add and remove Gtk::Widgets (for the time being just Gtk::Images and Gtk::Labels) to and from the Fixed container.
> I add with Fixed::put(), and remove with Container::remove() -as there is no specific remove method in Fixed.
> The troubles arise when I try to add again something that I had previously removed. In this case I get assertion fail and segmentation fault.

That happens because Container::remove() unreferences the widgets. Nothing
else references them, therefore they are destroyed.

> Can anyone suggest why?
> Is there any other way of doing what I need? (in worse case, if adviceable, I might go for some other library/toolkit...)

Instead of adding/removing, you could simply call Widget::show() and
Widget::hide().

> If it can be usefut: I keep track of the widgets that I display with a collection of pointers to Gtk::Widget, then I use this collection to compare what I want to display next with what I have on screen, and then add, move or remove elements.

Use Glib::RefPtr<Gtk::Widget> to keep track of them....

> Thank you very much in advance.
> Enrico

-- 
Bassoukos Tassos   +30 31 996011 / +30 93 7109954       IT Generalist

C++: an octopus made by nailing extra legs onto a dog
                                      -- Steve Taylor, 1998




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