Re: [gtkmm] Q: How to dynamically change label and callback of a Gtk::MenuItem at runtime?



Mirco Müller wrote:
Greetings everybody!

	Well, the subject asks it all. I'm trying to figure out how to
correctly change the callback and label of an already created
Gtk::MenuItem. At the moment it looks like I have to completely replace
the Gtk::MenuItem with a new one.

Thanks in advance for your time and kind advice!


Never did it myself, but since a MenuItem is just a Bin, you'd use get_child() to get to whatever is inside the MenuItem, which I suppose would be a Label for a "plain" MenuItem. So something like:

  Gtk::Label* label = dynamic_cast<Gtk::Label*>(menu_item.get_child());
  if (label) {
    label->set_text("foobar");
  }

Possibly, there'd be an Alignment involved as well, so you'd might have to tweak that a bit.

As with changing the "callback", it appears that SignalProxy doesn't provide a way of removing a connected signal handler, so you'd probably need to proxy the callback through your own code that would handle that.

You may want to use Actions, which I suppose would handle what you're after out of the box.

--
Christer Palm



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