Synopsis
#include <gtk/gtk.h>
GtkToggleButton;
GtkWidget* gtk_toggle_button_new (void);
GtkWidget* gtk_toggle_button_new_with_label (const gchar *label);
GtkWidget* gtk_toggle_button_new_with_mnemonic (const gchar *label);
void gtk_toggle_button_set_mode (GtkToggleButton *toggle_button,
gboolean draw_indicator);
gboolean gtk_toggle_button_get_mode (GtkToggleButton *toggle_button);
#define gtk_toggle_button_set_state
void gtk_toggle_button_toggled (GtkToggleButton *toggle_button);
gboolean gtk_toggle_button_get_active (GtkToggleButton *toggle_button);
void gtk_toggle_button_set_active (GtkToggleButton *toggle_button,
gboolean is_active);
gboolean gtk_toggle_button_get_inconsistent (GtkToggleButton *toggle_button);
void gtk_toggle_button_set_inconsistent (GtkToggleButton *toggle_button,
gboolean setting);
Object Hierarchy
GObject
+----GInitiallyUnowned
+----GtkObject
+----GtkWidget
+----GtkContainer
+----GtkBin
+----GtkButton
+----GtkToggleButton
+----GtkCheckButton
Properties"active" gboolean : Read / Write "draw-indicator" gboolean : Read / Write "inconsistent" gboolean : Read / Write DescriptionA GtkToggleButton is a GtkButton 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 state of a GtkToggleButton can be set specifically using
To simply switch the state of a toggle button, use gtk_toggle_button_toggled. Example 13. Creating two GtkToggleButton widgets.
void make_toggles (void) {
GtkWidget *dialog, *toggle1, *toggle2;
dialog = gtk_dialog_new ();
toggle1 = gtk_toggle_button_new_with_label ("Hi, i'm a toggle button.");
/* Makes this toggle button invisible */
gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (toggle1), TRUE);
g_signal_connect (toggle1, "toggled",
G_CALLBACK (output_state), NULL);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area),
toggle1, FALSE, FALSE, 2);
toggle2 = gtk_toggle_button_new_with_label ("Hi, i'm another toggle button.");
gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (toggle2), FALSE);
g_signal_connect (toggle2, "toggled",
G_CALLBACK (output_state), NULL);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area),
toggle2, FALSE, FALSE, 2);
gtk_widget_show_all (dialog);
}
DetailsGtkToggleButtontypedef struct _GtkToggleButton GtkToggleButton; The GtkToggleButton struct contains private data only, and should be manipulated using the functions below. gtk_toggle_button_new ()GtkWidget* gtk_toggle_button_new (void);
Creates a new toggle button. A widget should be packed into the button, as in
gtk_toggle_button_new_with_label ()GtkWidget* gtk_toggle_button_new_with_label (const gchar *label); Creates a new toggle button with a text label.
gtk_toggle_button_new_with_mnemonic ()GtkWidget* gtk_toggle_button_new_with_mnemonic (const gchar *label);
Creates a new GtkToggleButton containing a label. The label
will be created using
gtk_toggle_button_set_mode ()void gtk_toggle_button_set_mode (GtkToggleButton *toggle_button, gboolean draw_indicator);
Sets whether the button is displayed as a separate indicator and label.
You can call this function on a checkbutton or a radiobutton with
This function only affects instances of classes like GtkCheckButton and GtkRadioButton that derive from GtkToggleButton, not instances of GtkToggleButton itself.
gtk_toggle_button_get_mode ()gboolean gtk_toggle_button_get_mode (GtkToggleButton *toggle_button);
Retrieves whether the button is displayed as a separate indicator
and label. See
gtk_toggle_button_set_state#define gtk_toggle_button_set_state gtk_toggle_button_set_active Warning
This is a deprecated macro, and is only maintained for compatibility reasons. gtk_toggle_button_toggled ()void gtk_toggle_button_toggled (GtkToggleButton *toggle_button); Emits the toggled signal on the GtkToggleButton. There is no good reason for an application ever to call this function.
gtk_toggle_button_get_active ()gboolean gtk_toggle_button_get_active (GtkToggleButton *toggle_button);
Queries a GtkToggleButton and returns its current state. Returns
gtk_toggle_button_set_active ()void gtk_toggle_button_set_active (GtkToggleButton *toggle_button, gboolean is_active);
Sets the status of the toggle button. Set to
gtk_toggle_button_get_inconsistent ()gboolean gtk_toggle_button_get_inconsistent (GtkToggleButton *toggle_button);
Gets the value set by
gtk_toggle_button_set_inconsistent ()void gtk_toggle_button_set_inconsistent (GtkToggleButton *toggle_button, gboolean setting);
If the user has selected a range of elements (such as some text or
spreadsheet cells) that are affected by a toggle button, and the
current values in that range are inconsistent, you may want to
display the toggle in an "in between" state. This function turns on
"in between" display. Normally you would turn off the inconsistent
state again if the user toggles the toggle button. This has to be
done manually,
Property DetailsThe
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
the object which received the signal. |
|
user data set when the signal handler was connected. |
a more general button. |
|
another way of presenting a toggle option. |
|
a GtkToggleButton as a menu item. |