Calling Gtk::ToggleToolButton's set_icon_widget() multiple times
- From: Ruud Beukema <ruudbeukema gmail com>
- To: gtkmm-list gnome org
- Subject: Calling Gtk::ToggleToolButton's set_icon_widget() multiple times
- Date: Sat, 07 Nov 2009 15:25:50 +0100
Hi all,
I'm new to this mailing-list (and quite new to Gtkmm programming too),
but I joined because I have a problem to which I couldn't find an answer
through your mailing-list-archives and best friend Google.
My goal is to add a Gtk::ToggleToolButton to a Gtk::Toolbar (this
works). The Gtk::ToggleToolButton should show icon #1 in its non-active
(raised) state and icon #2 in its active (pressed) state. Here's how I
tried to accomplish this in class Foo:
----------------------------------------------------------------
/* Class Foo's private variables */
Gtk::ToggleToolButton mToggleToolButton;
Gtk::Image *pImage;
/* Class Foo's constructor */
Foo::Foo()
{
// In this constructor the ToggleToolButton is successfully set to have
the default icon
Glib::RefPtr<Gdk::Pixbuf> im =
Gdk::Pixbuf::create_from_file("path_to_icon_1", 22, 22, true);
pImage = manage(new Gtk::Image(im));
mToggleToolButton.set_icon_widget(*pImage);
mToggleToolButton.signal_toggled().connect( sigc::mem_fun(*this,
&Foo::on_toggletoolbutton_toggled) );
}
void Foo::on_toggletoolbutton_toggled()
{
if ( mToggleToolButton.get_active() )
{
// Here I try to replace the ToggleToolButton's icon
Glib::RefPtr<Gdk::Pixbuf> im =
Gdk::Pixbuf::create_from_file("path_to_icon_2", 22, 22, true);
pImage = manage(new Gtk::Image(im));
mToggleToolButton.set_icon_widget(*pImage);
}
else
{
// Icon #1 again
}
}
----------------------------------------------------------------
I've tried the above with and without the Gtk::manage() function, both
with no luck: when the ToggleToolButton is toggled for the first time
after construction, icon #1 is removed as expected but not replaced with
icon #2. Maybe needless to say, but when the ToggleToolButton is toggled
for a second time or more it remains without icon.
What am I doing wrong here? Or can Gtk::ToggleToolButton be only set to
have an icon once? Hope you can help me out!
Regards,
Ruud
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]