Package: gtk

Class gtk-radio-button

Superclasses

Documented Subclasses

None

Direct Slots

group
The group property of type gtk-radio-button (Write)
Sets a new group for a radio button.

Details

A single radio button performs the same basic function as a gtk-check-button widget, 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 gtk-radio-button widget is one way of giving the user a choice from many options.

Radio buttons are created with the gtk-radio-button-new function, passing nil 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, the gtk-radio-button-new-with-label function 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 the gtk-radio-button-new-from-widget function with a gtk-radio-button widget that already has a group assigned to it. The convenience gtk-radio-button-new-with-label-from-widget function is also provided.

To retrieve the group a gtk-radio-button widget is assigned to, use the gtk-radio-button-get-group function.

To remove a gtk-radio-button widget from one group and make it part of a new one, use the gtk-radio-button-set-group function.

CSS nodes

 radiobutton
 ├── radio
 ╰── <child>    
A gtk-radio-button widget with indicator, see the gtk-toggle-button-mode function, has a main CSS node with name radiobutton and a subnode with name radio.
 button.radio
 ├── radio
 ╰── <child>    
A gtk-radio-button implementation 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.

Example

How to create a group of two radio buttons.
(defun example-radio-button ()
  (within-main-loop
    (let ((window (make-instance 'gtk-window
                                 :type :toplevel
                                 :title "Example Radio Button"
                                 :border-width 12
                                 :default-width 300
                                 :default-height 120))
          (grid (make-instance 'gtk-grid
                               :orientation :vertical
                               :halign :center
                               :valign :center
                               :row-spacing 18)))

(g-signal-connect window "destroy" (lambda (widget) (declare (ignore widget)) (leave-gtk-main)))

(let ((radio (gtk-radio-button-new nil))) (gtk-container-add radio (gtk-entry-new)) (gtk-container-add grid radio) (setf radio (gtk-radio-button-new-with-label-from-widget radio "Second Button")) (gtk-container-add grid radio))

(gtk-container-add window grid) (gtk-widget-show-all window))))
When an unselected radio button in the group is clicked the clicked radio button receives the "toggled" signal, as does the previously selected radio button. Inside the "toggled" handler, the gtk-toggle-button-active function can be used to determine if the button has been selected or deselected.

Signal Details

The "group-changed" signal
 lambda (button)    :run-first      
Emitted when the group of radio buttons that a radio button belongs to changes. This is emitted when a radio button switches from being alone to being part of a group of two or more buttons, or vice-versa, and when a button is moved from one group of two or more buttons to a different one, but not when the composition of the group that a button belongs to changes.
button
The gtk-radio-button widget which received the signal.
 

Slot Access Functions

Inherited Slot Access Functions

See also

*2021-12-4