Package: gtk

Class gtk-toggle-button

Superclasses

Documented Subclasses

Direct Slots

active
The active property of type :boolean (Read / Write)
If the toggle button should be pressed in.
Default value: false
draw-indicator
The draw-indicator property of type :boolean (Read / Write)
If the toggle part of the button is displayed.
Default value: false
inconsistent
The inconsistent property of type :boolean (Read / Write)
If the toggle button is in an "in between" state.
Default value: false

Details

A gtk-toggle-button widget is a gtk-button widget which will remain "pressed-in" when clicked. Clicking again will cause the toggle button to return to its normal state.



A toggle button is created by calling either the gtk-toggle-button-new or gtk-toggle-button-new-with-label functions. If using the former, it is advisable to pack a widget, such as a gtk-label or a gtk-image widget, into the container of the toggle button. See the gtk-button widget for more information.

The state of a gtk-toggle-button widget can be set and retrieved using the gtk-toggle-button-active function.

To simply switch the state of a toggle button, use the gtk-toggle-button-toggled function.

CSS nodes

The gtk-toggle-button implementation has a single CSS node with name button. To differentiate it from a plain button, it gets the .toggle style class.

Example

This example from the GTK tutorial has two toggle buttons. The toggle buttons are used to switch the column and row spacing of a grid.
(defun example-grid-spacing ()
  (within-main-loop
    (let ((window (make-instance 'gtk-window
                                 :type :toplevel
                                 :title "Example Grid Spacing"
                                 :border-width 12
                                 :default-width 320))
          (grid (make-instance 'gtk-grid
                               :column-homogeneous t
                               :column-spacing 6
                               :row-homogeneous t
                               :row-spacing 6))
          (button1 (make-instance 'gtk-toggle-button
                                  :label "More Row Spacing"))
          (button2 (make-instance 'gtk-toggle-button
                                  :label "More Col Spacing"))
          (button3 (make-instance 'gtk-button
                                  :label "Button 3")))

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

(g-signal-connect button1 "toggled" (lambda (widget) (if (gtk-toggle-button-active widget) (progn (setf (gtk-grid-row-spacing grid) 24) (setf (gtk-button-label widget) "Less Row Spacing")) (progn (setf (gtk-grid-row-spacing grid) 6) (setf (gtk-button-label widget) "More Row Spacing"))))) (g-signal-connect button2 "toggled" (lambda (widget) (if (gtk-toggle-button-active widget) (progn (setf (gtk-grid-column-spacing grid) 24) (setf (gtk-button-label widget) "Less Col Spacing")) (progn (setf (gtk-grid-column-spacing grid) 6) (setf (gtk-button-label widget) "More Col Spacing")))))

(gtk-grid-attach grid button1 0 0 1 1) (gtk-grid-attach grid button2 1 0 1 1) (gtk-grid-attach grid button3 0 1 2 1)

(gtk-container-add window grid) (gtk-widget-show-all window))))

Signal Details

The "toggled" signal
 lambda (togglebutton)    :run-first      
Should be connected if you wish to perform an action whenever the state of the toggle button is changed.
togglebutton
The gtk-toggle-button widget which received the signal.
 

Slot Access Functions

Inherited Slot Access Functions

See also

*2021-10-11