LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-30-2010, 12:20 PM   #1
Puneet Jindal
Member
 
Registered: Aug 2010
Location: India(Punjab)
Posts: 38

Rep: Reputation: 0
Radio button problem in Gtkmm 2.4


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

Last edited by Puneet Jindal; 12-30-2010 at 12:22 PM.
 
Old 01-02-2011, 09:29 PM   #2
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,541

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
When you select a radio button, two events are generated in the following order:

1. The selected radio button is made active
2. Another radio button is made inactive

When each event is generated, your code is determining that a particular radio button (in this case, the one selected) is active, and this explains why you see the same message appear twice.

If all you want to do is perform an action when a particular radio box is selected, then you should consider setting up the callback function to accept a Gtk::RadioButton widget. Using the widget and then checking if it is active should be sufficient for your needs.

Read more here on how to pass information (eg. RadioButton widget) to your callback routine.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] insert radio button on panel? Manish87 Linux - Newbie 1 07-31-2010 04:29 AM
GTKMM custom widget draw standard button style background gafferuk Programming 4 04-01-2009 10:23 AM
2 jtextField must work like radio button groups xface66 Programming 2 09-11-2007 09:54 AM
how can I find the length of all radio button? rblampain Programming 3 08-12-2007 09:35 PM
php radio button question jabfinger Programming 5 08-14-2005 10:36 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:51 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration