Top | ![]() |
![]() |
![]() |
![]() |
GtkWidget * | gtk_button_new () |
GtkWidget * | gtk_button_new_with_label () |
GtkWidget * | gtk_button_new_with_mnemonic () |
GtkWidget * | gtk_button_new_from_icon_name () |
void | gtk_button_clicked () |
void | gtk_button_set_relief () |
GtkReliefStyle | gtk_button_get_relief () |
const gchar * | gtk_button_get_label () |
void | gtk_button_set_label () |
gboolean | gtk_button_get_use_underline () |
void | gtk_button_set_use_underline () |
void | gtk_button_set_icon_name () |
const char * | gtk_button_get_icon_name () |
gchar * | icon-name | Read / Write |
gchar * | label | Read / Write |
GtkReliefStyle | relief | Read / Write |
gboolean | use-underline | Read / Write |
GObject ╰── GInitiallyUnowned ╰── GtkWidget ╰── GtkContainer ╰── GtkBin ╰── GtkButton ├── GtkToggleButton ├── GtkColorButton ├── GtkFontButton ├── GtkLinkButton ├── GtkLockButton ├── GtkModelButton ╰── GtkScaleButton
The GtkButton widget is generally used to trigger a callback function that is called when the button is pressed. The various signals and how to use them are outlined below.
The GtkButton widget can hold any valid child widget. That is, it can hold almost any other standard GtkWidget. The most commonly used child is the GtkLabel.
GtkButton has a single CSS node with name button. The node will get the style classes .image-button or .text-button, if the content is just an image or label, respectively. It may also receive the .flat style class.
Other style classes that are commonly used with GtkButton include .suggested-action and .destructive-action. In special cases, buttons can be made round by adding the .circular style class.
Button-like widgets like GtkToggleButton, GtkMenuButton, GtkVolumeButton, GtkLockButton, GtkColorButton, GtkFontButton or GtkFileChooserButton use style classes such as .toggle, .popup, .scale, .lock, .color, .font, .file to differentiate themselves from a plain GtkButton.
GtkWidget *
gtk_button_new (void
);
Creates a new GtkButton widget. To add a child widget to the button,
use gtk_container_add()
.
GtkWidget *
gtk_button_new_with_label (const gchar *label
);
Creates a GtkButton widget with a GtkLabel child containing the given text.
GtkWidget *
gtk_button_new_with_mnemonic (const gchar *label
);
Creates a new GtkButton containing a label.
If characters in label
are preceded by an underscore, they are underlined.
If you need a literal underscore character in a label, use “__” (two
underscores). The first underlined character represents a keyboard
accelerator called a mnemonic.
Pressing Alt and that key activates the button.
GtkWidget * gtk_button_new_from_icon_name (const gchar *icon_name
,GtkIconSize size
);
Creates a new button containing an icon from the current icon theme.
If the icon name isn’t known, a “broken image” icon will be displayed instead. If the current icon theme is changed, the icon will be updated appropriately.
Since: 3.10
void gtk_button_set_relief (GtkButton *button
,GtkReliefStyle relief
);
Sets the relief style of the edges of the given GtkButton widget.
Two styles exist, GTK_RELIEF_NORMAL
and GTK_RELIEF_NONE
.
The default style is, as one can guess, GTK_RELIEF_NORMAL
.
button |
The GtkButton you want to set relief styles of |
|
relief |
The GtkReliefStyle as described above |
GtkReliefStyle
gtk_button_get_relief (GtkButton *button
);
Returns the current relief style of the given GtkButton.
const gchar *
gtk_button_get_label (GtkButton *button
);
Fetches the text from the label of the button, as set by
gtk_button_set_label()
. If the label text has not
been set the return value will be NULL
. This will be the
case if you create an empty button with gtk_button_new()
to
use as a container.
void gtk_button_set_label (GtkButton *button
,const gchar *label
);
Sets the text of the label of the button to label
.
This will also clear any previously set labels.
gboolean
gtk_button_get_use_underline (GtkButton *button
);
Returns whether an embedded underline in the button label indicates a
mnemonic. See gtk_button_set_use_underline()
.
void gtk_button_set_use_underline (GtkButton *button
,gboolean use_underline
);
If true, an underline in the text of the button label indicates the next character should be used for the mnemonic accelerator key.
void gtk_button_set_icon_name (GtkButton *button
,const char *icon_name
);
Adds a GtkImage with the given icon name as a child. The icon will be
of size GTK_ICON_SIZE_BUTTON
. If button
already contains a child widget,
that child widget will be removed and replaced with the image.
Since: 3.90
const char *
gtk_button_get_icon_name (GtkButton *button
);
Returns the icon name set via gtk_button_set_icon_name()
.
Since: 3.90
“icon-name”
property“icon-name” gchar *
The name of the icon used to automatically populate the button.
Flags: Read / Write
Default value: NULL
“label”
property“label” gchar *
Text of the label widget inside the button, if the button contains a label widget.
Flags: Read / Write
Default value: NULL
“relief”
property“relief” GtkReliefStyle
The border relief style.
Flags: Read / Write
Default value: GTK_RELIEF_NORMAL
“use-underline”
property“use-underline” gboolean
If set, an underline in the text indicates the next character should be used for the mnemonic accelerator key.
Flags: Read / Write
Default value: FALSE
“activate”
signalvoid user_function (GtkButton *widget, gpointer user_data)
The ::activate signal on GtkButton is an action signal and emitting it causes the button to animate press then release. Applications should never connect to this signal, but use the “clicked” signal.
widget |
the object which received the signal. |
|
user_data |
user data set when the signal handler was connected. |
Flags: Action