Re: help on array of widgets



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

buttons.back()->signal_clicked().connect(sigc_bind(sigc::mem_fun(*this,
> &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
{
	public:
		MyButton(const Glib::ustring &name, int some_id):
			Gtk::Button(name),
			id(some_id)
		{ }
		int get_id() const { return id; }
	private:
		int id;
};
std::vector<MyButton*> buttons;
etc.

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:
(*buttons.back()).signal_clicked().connect(sigc::mem_fun(*this,
&HelloWorld::onButtonsClick));
//...
void HelloWorld::onButtonsClick() {
//who was clicked?!?
}


Regards.

Mj Mendoza IV,
Developer, KonsolScript
http://www.konsolscript.org


------------------------------------------------------------------------
*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.

Yann



_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list


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