Struct gtk::RadioButton[][src]

pub struct RadioButton(_);
Expand description

A single radio button performs the same basic function as a CheckButton, as its position in the object hierarchy reflects. It is only when multiple radio buttons are grouped together that they become a different user interface component in their own right.

Every radio button is a member of some group of radio buttons. When one is selected, all other radio buttons in the same group are deselected. A RadioButton is one way of giving the user a choice from many options.

Radio button widgets are created with new(), passing None as the argument if this is the first radio button in a group. In subsequent calls, the group you wish to add this button to should be passed as an argument. Optionally, with_label() can be used if you want a text label on the radio button.

Alternatively, when adding widgets to an existing group of radio buttons, use from_widget() with a RadioButton that already has a group assigned to it. The convenience function with_label_from_widget() is also provided.

To retrieve the group a RadioButton is assigned to, use RadioButtonExt::group().

To remove a RadioButton from one group and make it part of a new one, use gtk_radio_button_set_group().

The group list does not need to be freed, as each RadioButton will remove itself and its list item when it is destroyed.

CSS nodes

⚠️ The following code is in plain ⚠️

radiobutton
├── radio
╰── <child>

A GtkRadioButton with indicator (see ToggleButtonExt::set_mode()) has a main CSS node with name radiobutton and a subnode with name radio.

⚠️ The following code is in plain ⚠️

button.radio
├── radio
╰── <child>

A GtkRadioButton without indicator changes the name of its main node to button and adds a .radio style class to it. The subnode is invisible in this case.

How to create a group of two radio buttons.

⚠️ The following code is in C ⚠️

void create_radio_buttons (void) {

   GtkWidget *window, *radio1, *radio2, *box, *entry;
   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
   gtk_box_set_homogeneous (GTK_BOX (box), TRUE);

   // Create a radio button with a GtkEntry widget
   radio1 = gtk_radio_button_new (NULL);
   entry = gtk_entry_new ();
   gtk_container_add (GTK_CONTAINER (radio1), entry);


   // Create a radio button with a label
   radio2 = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio1),
                                                         "I’m the second radio button.");

   // Pack them into a box, then show all the widgets
   gtk_box_pack_start (GTK_BOX (box), radio1);
   gtk_box_pack_start (GTK_BOX (box), radio2);
   gtk_container_add (GTK_CONTAINER (window), box);
   gtk_widget_show_all (window);
   return;
}

When an unselected button in the group is clicked the clicked button receives the signal::ToggleButton::toggled signal, as does the previously selected button. Inside the signal::ToggleButton::toggled handler, ToggleButtonExt::is_active() can be used to determine if the button has been selected or deselected.

Implements

RadioButtonExt, [CheckButtonExt][trait@crate::prelude::CheckButtonExt], ToggleButtonExt, ButtonExt, BinExt, ContainerExt, WidgetExt, glib::ObjectExt, BuildableExt, ActionableExt, WidgetExtManual, BuildableExtManual

Implementations

Creates a new RadioButton, adding it to the same group as radio_group_member. As with new(), a widget should be packed into the radio button.

radio_group_member

an existing RadioButton.

Returns

a new radio button.

Creates a new RadioButton with a text label, adding it to the same group as radio_group_member.

radio_group_member

widget to get radio group from or None

label

a text string to display next to the radio button.

Returns

a new radio button.

Creates a new RadioButton containing a label. The label will be created using Label::with_mnemonic(), so underscores in label indicate the mnemonic for the button.

radio_group_member

widget to get radio group from or None

label

the text of the button, with an underscore in front of the mnemonic character

Returns

a new RadioButton

Creates a new builder-pattern struct instance to construct RadioButton objects.

This method returns an instance of RadioButtonBuilder which can be used to create RadioButton objects.

Creates a new RadioButton. To be of any practical value, a widget should then be packed into the radio button.

group

an existing radio button group, or None if you are creating a new group.

Returns

a new radio button

Creates a new RadioButton with a text label.

group

an existing radio button group, or None if you are creating a new group.

label

the text label to display next to the radio button.

Returns

a new radio button.

Creates a new RadioButton containing a label, adding it to the same group as group. The label will be created using Label::with_mnemonic(), so underscores in label indicate the mnemonic for the button.

group

the radio button group, or None

label

the text of the button, with an underscore in front of the mnemonic character

Returns

a new RadioButton

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Formats the value using the given formatter. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Returns the type identifier of Self.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Upcasts an object to a superclass or interface T. Read more

Upcasts an object to a reference of its superclass or interface T. Read more

Tries to downcast to a subclass or interface implementor T. Read more

Tries to downcast to a reference of its subclass or interface implementor T. Read more

Tries to cast to an object of type T. This handles upcasting, downcasting and casting between interface and interface implementors. All checks are performed at runtime, while downcast and upcast will do many checks at compile-time already. Read more

Tries to cast to reference to an object of type T. This handles upcasting, downcasting and casting between interface and interface implementors. All checks are performed at runtime, while downcast and upcast will do many checks at compile-time already. Read more

Casts to T unconditionally. Read more

Casts to &T unconditionally. Read more

Performs the conversion.

Performs the conversion.

Returns true if the object is an instance of (can be cast to) T.

Safety Read more

Safety Read more

Safety Read more

Safety Read more

Safety Read more

Safety Read more

Same as connect but takes a SignalId instead of a signal name.

Same as connect_local but takes a SignalId instead of a signal name.

Same as connect_unsafe but takes a SignalId instead of a signal name.

Emit signal by signal id.

Emit signal with details by signal id.

Emit signal by it’s name.

Same as emit but takes Value for the arguments.

Same as emit_by_name but takes Value for the arguments.

Same as emit_with_details but takes Value for the arguments.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Returns a SendValue clone of self.

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.