[gtkmm] Label in a std::list<Gtk::button *>



I've tried to debug for three days but i cannot find the solution.
I want make a list of buttons and set the label. The code compiles and
works for the event but does not set the labels of buttons.

I force the label twice: with the constructor and with the set_label


Any suggestion

Thanks 
	Alberto Paro

PS: the code is based of the button example of gtkmm.





-- 
Alberto Paro <alberto paro homeunix org>
#include <gtkmm/main.h>
#include <iostream>
#include <sstream>

#include <gtkmm.h>
#include <list>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  virtual ~ExampleWindow();

protected:
  //Signal handlers:
  virtual void on_button_quit();
  virtual void on_button_numbered(Glib::ustring data);

  //Child widgets:
  Gtk::Table *m_Table;
  std::list<Gtk::Button*> buttons;
  Gtk::Button *m_Button_1, m_Button_2, m_Button_Quit;

};



ExampleWindow::ExampleWindow()
:   m_Button_2("butt"),
  m_Button_Quit("Quit")
{
  set_title("Gtk::Table");
  set_border_width(20);
  m_Table=new Gtk::Table(7, 2, true);
	m_Button_1=new Gtk::Button("button 1");
  m_Table->attach(*m_Button_1, 0, 1, 0, 1);
  m_Table->attach(m_Button_2, 1, 2, 0, 1);
  m_Table->attach(m_Button_Quit, 0, 2, 1, 2);

  int i;
  std::ostringstream output(std::ios::ate);
   Glib::ustring label;
  for( i=0;i<3 ;i++ ){
	 output.str("");
	 output<<i*2;
	label=output.str();
	 buttons.push_front(new Gtk::Button(label)); //should set label
	std::list<Gtk::Button*>::iterator it;

	it=buttons.begin();
 	(*it)->set_label(label); //should set label
	 (*it)->signal_clicked().connect(
      SigC::bind<Glib::ustring>( SigC::slot(*this, &ExampleWindow::on_button_numbered), label) );
  m_Table->attach(*(*it), 0, 1, 0, i+3);

  }

  m_Button_1->signal_clicked().connect(
      SigC::bind<Glib::ustring>( SigC::slot(*this, &ExampleWindow::on_button_numbered), "button 1") );
  m_Button_2.signal_clicked().connect(
      SigC::bind<Glib::ustring>( SigC::slot(*this, &ExampleWindow::on_button_numbered), "button 2") );

  m_Button_Quit.signal_clicked().connect( SigC::slot(*this, &ExampleWindow::on_button_quit) );

  add(*m_Table);
  show_all_children();
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_button_quit()
{
  hide();
}

void
ExampleWindow::on_button_numbered(Glib::ustring data)
{
  std::cout << "Hello again - " << data << " was pressed" << std::endl;
}


int main(int argc, char *argv[])
{
  Gtk::Main kit(argc, argv);

  ExampleWindow window;
  Gtk::Main::run(window); //Shows the window and returns when it is closed.

  return 0;
}


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