Re: Simple(?) pixmap problem

Todd Pafford <> writes:

> Hi all, I've just started working with GTK and am still playing with
> things to get the feel of how it works.  My latest little test program is
> giving me headaches though and I'm wondering if I'm doing things
> correctly. Instead of describing what I've tried and making an
> unecessarily long post, perhaps I can describe what I want and someone
> could chime in with the best way of doing it?
> Here's the deal:  I've got a small window, just large enough to hold a
> 47x47 pixmap (we'll call this pixmap1).  When I click on the pixmap, I
> want it to change to pixmap2...another click, back to pixmap1...just
> toggling between the two.  Setting up the window and displaying pixmap1
> works fine, it's the toggling that's not working.  The callback's getting
> called fine, it seems to be the process of removing pixmap1 and adding
> pixmap2 (and vice versa) that's failing. What are the steps I should take
> to change from one pixmap to the other?

  gtk_pixmap_set (GTK_PIXMAP (pixmap_widget), new_pixmap, NULL);

Should be all that is necessary. What isn't working for you?

Perhaps reference counting is causing problems for you. Each
GdkPixmap is created with a reference count of one. Adding
the GdkPixmap to the Pixmap widget incremements the reference
count, removing it (or replacing it) decrements the reference

So, if you are decrementing the reference count (gdk_pixmap_unref())
yourself after initially adding it to the pixmap widget, then the
GdkPixmap would be freed when it was removed from the pixmap widget.

In this case, you just want to decrement the reference counts
when you are all done with both pixmaps. But that's just
a wild guess.


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