Re: help on array of widgets

In Gtkmm you have to pass a parameter to the callback using sigc::bind():

> &HelloWorld::onButtonsClick), buttons.back()));

void HelloWorld::onButtonsClick(Gtk::Button *but)

At this point, if you want to attach data to each button, you may want to create a subclass of Gtk::Button, eg:
class MyButton: public Gtk::Button
		MyButton(const Glib::ustring &name, int some_id):
		{ }
		int get_id() const { return id; }
		int id;
std::vector<MyButton*> buttons;

On 27/07/11 14:18, Mj Mendoza IV wrote:
Thanks for the snippet Yann!

Now how do I properly handle which button was clicked?

What I did was:
void HelloWorld::onButtonsClick() {
//who was clicked?!?


Mj Mendoza IV,
Developer, KonsolScript

*From:* Yann Leydier <yann leydier info>
*To:* gtkmm-list gnome org
*Sent:* Wednesday, July 27, 2011 7:30:48 PM
*Subject:* Re: help on array of widgets

It is the exact opposite ! :o)

std::vector<Gtk::Button*> buttons;
buttons.push_back(Gtk::manage(new Gtk::Button("but")));
vbox.pack_start(*buttons.back(), …

Calling Gtk::manage(widget_pointer) will cause the widget to be freed
when its parent is destroyed.

Glib::RefPtr is generally not to be used when the API does not force you
to use it.


gtkmm-list mailing list
gtkmm-list gnome org

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