class SRadioButton : public Gtk::Window
{
public:
SRadioButton(string str = "Go to hell from ToggleButton")
{
SimpleRadioButton1 = new Gtk::RadioButton("Super Saiyan One");
SimpleRadioButton2 = new Gtk::RadioButton("Super Saiyan Two");
SimpleRadioButton3 = new Gtk::RadioButton("Super Saiyan Three");
Gtk::RadioButton::Group group = SimpleRadioButton1->get_group();
SimpleRadioButton2->set_group(group);
SimpleRadioButton3->set_group(group);
SimpleRadioButton4 = Gtk::manage(new Gtk::RadioButton(group,"Super Saiyan Four"));
set_title("My application");
set_border_width(10);
SimpleRadioButton1->set_active();
SimpleRadioButton1->signal_clicked().connect( sigc::mem_fun(*this,&SRadioButton:
n_button_clicked) );
SimpleRadioButton2->signal_clicked().connect( sigc::mem_fun(*this,&SRadioButton:
n_button_clicked) );
SimpleRadioButton3->signal_clicked().connect( sigc::mem_fun(*this,&SRadioButton:
n_button_clicked) );
SimpleRadioButton4->signal_clicked().connect( sigc::mem_fun(*this,&SRadioButton:
n_button_clicked) );
add(outer_box);
outer_box.pack_start(*SimpleRadioButton1);
outer_box.pack_start(*SimpleRadioButton2);
outer_box.pack_start(*SimpleRadioButton3);
outer_box.pack_start(*SimpleRadioButton4);
show_all_children();
}
virtual ~SRadioButton(){}
protected:
void on_button_clicked()
{
string str;
if(SimpleRadioButton1->get_active() == true)
{
str = SimpleRadioButton1->get_label() + " level reached";
}
else if(SimpleRadioButton2->get_active() == true)
{
str = SimpleRadioButton2->get_label() + " level reached";
}
else if(SimpleRadioButton3->get_active() == true)
{
str = SimpleRadioButton3->get_label() + " level reached";
}
else if(SimpleRadioButton4->get_active() == true)
{
str = SimpleRadioButton4->get_label() + " level reached";
}
cout<<str<<endl;
}
Gtk::RadioButton *SimpleRadioButton1,*SimpleRadioButton2,*SimpleRadioButton3,*SimpleRadioButton4;
Gtk::VBox outer_box;
};
Note:-Form has VBox widget containing these four radiobuttons only.
Problem:- When I click on a different button the message is printed twice.I actually want to select a radio button and want to print his label as the message only once.Please correct me if I am wrong.Thanks........