Re: Gtk::Button set_image()
- From: Daniel Elstner <daniel kitta googlemail com>
- To: Caroline Kierstead <ctkierst cs uwaterloo ca>
- Cc: gtkmm mailing list <gtkmm-list gnome org>
- Subject: Re: Gtk::Button set_image()
- Date: Wed, 27 May 2009 20:54:33 +0200
Am Mittwoch, den 27.05.2009, 13:35 -0400 schrieb Caroline Kierstead:
> Daniel Elstner wrote:
> > Am Dienstag, den 26.05.2009, 18:05 -0400 schrieb Caroline Kierstead:
> >> Does anybody know why, if I pass in the same dereferenced pointer to a
> >> Gtk::Image to multiple Gtk::Button objects using set_image(), only the image in
> >> the most recent one is displayed? I didn't see a note about it in the reference
> >> manual, though I may have missed it.
> >
> > You should have seen a note in your console output, I think.
>
> Nope, nothing. I saw error messages about re-parenting when I had other errors,
> but not this one.
That's a bit odd, but it could be that set_image() doesn't do the same
checks as add() does. Though I'd have expected Gtk::Button to simply
use a Gtk::HBox internally and that's it. Ah well, maybe that has
changed.
> > As Jonathan said, a widget can only be in one container at the same
> > time. However, Gtk::Image itself doesn't hold the actual image data.
> > You can still have multiple Gtk::Image widgets sharing the same
> > Gdk::Pixbuf, or whatever representation you decide to use.
>
> Is there any advantage to doing it this way? The image comes from a pixmap file,
> and I didn't want to get into anything complex, or try to explain bitmasking
> since this is a sophomore-level course on C++. The graphics are being introduced
> to make the last assignment a little more interesting.
If you create the Gtk::Image objects directly with the name of the image
file, then GTK+ will have no way to know that these images are actually
the same. (It definitely doesn't hash the file name and monitor the
content for changes.)
Even for an introductory example, that would be pretty bad. It would be
sort of a "don't do that!" example. I guess you attempted to reuse the
Gtk::Image for the same reason. Well, a pixbuf would add one more
indirection, but you definitely won't need to explain bitmasking.
const Glib::RefPtr<Gdk::Pixbuf>
pixbuf = Gdk::Pixbuf::create("filename");
// ...
And then instead of the filename, pass that pixbuf to the Gtk::Image
constructor. Another idea would be to simply not use an external file
at all but stock icons. In that case you could avoid the indirection
and just use the predefined items in the Gtk::Stock namespace directly
with Gtk::Image.
Cheers,
--Daniel
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]