GtkButton — A widget that emits a signal when clicked on
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_set_has_frame () |
gboolean | gtk_button_get_has_frame () |
const char * | 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 () |
void | gtk_button_set_child () |
GtkWidget * | gtk_button_get_child () |
struct | GtkButton |
struct | GtkButtonClass |
GObject ╰── GInitiallyUnowned ╰── GtkWidget ╰── GtkButton ├── GtkLinkButton ├── GtkLockButton ╰── GtkToggleButton
GtkButton implements GtkAccessible, GtkBuildable, GtkConstraintTarget and GtkActionable.
#include <gtk/gtk.h>
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 or GtkFontButton use style classes such as .toggle, .popup, .scale, .lock, .color on the button node to differentiate themselves from a plain GtkButton.
GtkButton uses the GTK_ACCESSIBLE_ROLE_BUTTON role.
GtkWidget *
gtk_button_new (void
);
Creates a new GtkButton widget. To add a child widget to the button, use gtk_button_set_child()
.
The newly created GtkButton widget.
GtkWidget *
gtk_button_new_with_label (const char *label
);
Creates a GtkButton widget with a GtkLabel child containing the given text.
label | The text you want the GtkLabel to hold. |
The newly created GtkButton widget.
GtkWidget *
gtk_button_new_with_mnemonic (const char *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.
label | The text of the button, with an underscore in front of the mnemonic character |
a new GtkButton
GtkWidget *
gtk_button_new_from_icon_name (const char *icon_name
);
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.
icon_name | an icon name or | [nullable] |
a new GtkButton displaying the themed icon
void gtk_button_set_has_frame (GtkButton *button
,gboolean has_frame
);
Sets the style of the button. Buttons can has a flat appearance or have a frame drawn around them.
button | ||
has_frame | whether the button should have a visible frame |
gboolean
gtk_button_get_has_frame (GtkButton *button
);
Returns whether the button has a frame.
button |
TRUE
if the button has a frame
const char *
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.
button |
The text of the label widget. This string is owned by the widget and must not be modified or freed.
[nullable]
void gtk_button_set_label (GtkButton *button
,const char *label
);
Sets the text of the label of the button to label
.
This will also clear any previously set labels.
button | ||
label | a string |
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()
.
button |
TRUE
if an embedded underline in the button label indicates the mnemonic accelerator keys.
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.
button | ||
use_underline |
|
void gtk_button_set_icon_name (GtkButton *button
,const char *icon_name
);
Adds a GtkImage with the given icon name as a child. If button
already contains a child widget, that child widget will be removed and replaced with the image.
button | ||
icon_name | An icon name |
const char *
gtk_button_get_icon_name (GtkButton *button
);
Returns the icon name set via gtk_button_set_icon_name()
.
button |
struct GtkButton;
struct GtkButtonClass { GtkWidgetClass parent_class; void (* clicked) (GtkButton *button); void (* activate) (GtkButton *button); };
| Signal emitted when the button has been activated (pressed and released). | |
| Signal that causes the button to animate press then release. Applications should never connect to this signal, but use the |
“has-frame”
property“has-frame” gboolean
Whether the button has a frame.
Owner: GtkButton
Flags: Read / Write
Default value: TRUE
“icon-name”
property“icon-name” char *
The name of the icon used to automatically populate the button.
Owner: GtkButton
Flags: Read / Write
Default value: NULL
“label”
property“label” char *
Text of the label widget inside the button, if the button contains a label widget.
Owner: GtkButton
Flags: Read / Write
Default value: NULL
“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.
Owner: GtkButton
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
“clicked”
signalvoid user_function (GtkButton *button, gpointer user_data)
Emitted when the button has been activated (pressed and released).
button | the object that received the signal | |
user_data | user data set when the signal handler was connected. |
Flags: Action
© 2005–2020 The GNOME Project
Licensed under the GNU Lesser General Public License version 2.1 or later.
https://developer.gnome.org/gtk4/4.0/GtkButton.html