![]() |
![]() |
![]() |
GTK+ Reference Manual | ![]() |
---|---|---|---|---|
#include <gtk/gtk.h> GtkButton; GtkWidget* gtk_button_new (void); GtkWidget* gtk_button_new_with_label (const gchar *label); GtkWidget* gtk_button_new_with_mnemonic (const gchar *label); GtkWidget* gtk_button_new_from_stock (const gchar *stock_id); void gtk_button_pressed (GtkButton *button); void gtk_button_released (GtkButton *button); void gtk_button_clicked (GtkButton *button); void gtk_button_enter (GtkButton *button); void gtk_button_leave (GtkButton *button); void gtk_button_set_relief (GtkButton *button, GtkReliefStyle newstyle); GtkReliefStyle gtk_button_get_relief (GtkButton *button); const gchar* gtk_button_get_label (GtkButton *button); void gtk_button_set_label (GtkButton *button, const gchar *label); gboolean gtk_button_get_use_stock (GtkButton *button); void gtk_button_set_use_stock (GtkButton *button, gboolean use_stock); gboolean gtk_button_get_use_underline (GtkButton *button); void gtk_button_set_use_underline (GtkButton *button, gboolean use_underline); void gtk_button_set_focus_on_click (GtkButton *button, gboolean focus_on_click); gboolean gtk_button_get_focus_on_click (GtkButton *button); void gtk_button_set_alignment (GtkButton *button, gfloat xalign, gfloat yalign); void gtk_button_get_alignment (GtkButton *button, gfloat *xalign, gfloat *yalign); void gtk_button_set_image (GtkButton *button, GtkWidget *image); GtkWidget* gtk_button_get_image (GtkButton *button); void gtk_button_set_image_position (GtkButton *button, GtkPositionType position); GtkPositionType gtk_button_get_image_position (GtkButton *button);
GObject +----GInitiallyUnowned +----GtkObject +----GtkWidget +----GtkContainer +----GtkBin +----GtkButton +----GtkToggleButton +----GtkColorButton +----GtkFontButton +----GtkLinkButton +----GtkOptionMenu +----GtkScaleButton
"focus-on-click" gboolean : Read / Write "image" GtkWidget* : Read / Write "image-position" GtkPositionType : Read / Write "label" gchar* : Read / Write / Construct "relief" GtkReliefStyle : Read / Write "use-stock" gboolean : Read / Write / Construct "use-underline" gboolean : Read / Write / Construct "xalign" gfloat : Read / Write "yalign" gfloat : Read / Write
"child-displacement-x" gint : Read "child-displacement-y" gint : Read "default-border" GtkBorder* : Read "default-outside-border" GtkBorder* : Read "displace-focus" gboolean : Read "image-spacing" gint : Read "inner-border" GtkBorder* : Read "tree-view-separator-area" gint : Read
"activate" : Run First / Action "clicked" : Run First / Action "enter" : Run First "leave" : Run First "pressed" : Run First "released" : Run First
The GtkButton widget is generally used to attach a function to 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 most any other standard GtkWidget. The most commonly used child is the GtkLabel.
typedef struct _GtkButton GtkButton;
This should not be accessed directly. Use the accessor functions below.
GtkWidget* gtk_button_new (void);
Creates a new GtkButton widget. To add a child widget to the button,
use gtk_container_add()
.
Returns : | The newly created GtkButton widget. |
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.
label : |
The text of the button, with an underscore in front of the mnemonic character |
Returns : | a new GtkButton |
GtkWidget* gtk_button_new_from_stock (const gchar *stock_id);
Creates a new GtkButton containing the image and text from a stock item. Some stock ids have preprocessor macros like GTK_STOCK_OK and GTK_STOCK_APPLY.
If stock_id
is unknown, then it will be treated as a mnemonic
label (as for gtk_button_new_with_mnemonic()
).
stock_id : |
the name of the stock item |
Returns : | a new GtkButton |
void gtk_button_pressed (GtkButton *button);
Emits a "pressed" signal to the given GtkButton.
button : |
The GtkButton you want to send the signal to. |
void gtk_button_released (GtkButton *button);
Emits a "released" signal to the given GtkButton.
button : |
The GtkButton you want to send the signal to. |
void gtk_button_clicked (GtkButton *button);
Emits a "clicked" signal to the given GtkButton.
button : |
The GtkButton you want to send the signal to. |
void gtk_button_enter (GtkButton *button);
Emits a "enter" signal to the given GtkButton.
button : |
The GtkButton you want to send the signal to. |
void gtk_button_leave (GtkButton *button);
Emits a "leave" signal to the given GtkButton.
button : |
The GtkButton you want to send the signal to. |
void gtk_button_set_relief (GtkButton *button, GtkReliefStyle newstyle);
Sets the relief style of the edges of the given GtkButton widget. Three styles exist, GTK_RELIEF_NORMAL, GTK_RELIEF_HALF, GTK_RELIEF_NONE. The default style is, as one can guess, GTK_RELIEF_NORMAL.
button : |
The GtkButton you want to set relief styles of. |
newstyle : |
The GtkReliefStyle as described above. |
GtkReliefStyle gtk_button_get_relief (GtkButton *button);
Returns the current relief style of the given GtkButton.
button : |
The GtkButton you want the GtkReliefStyle from. |
Returns : | The current GtkReliefStyle |
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.
button : |
a GtkButton |
Returns : | The text of the label widget. This string is owned by the widget and must not be modified or freed. |
void gtk_button_set_label (GtkButton *button, const gchar *label);
Sets the text of the label of the button to str
. This text is
also used to select the stock item if gtk_button_set_use_stock()
is used.
This will also clear any previously set labels.
button : |
a GtkButton |
label : |
a string |
gboolean gtk_button_get_use_stock (GtkButton *button);
Returns whether the button label is a stock item.
button : |
a GtkButton |
Returns : | TRUE if the button label is used to
select a stock item instead of being
used directly as the label text.
|
void gtk_button_set_use_stock (GtkButton *button, gboolean use_stock);
If TRUE
, the label set on the button is used as a
stock id to select the stock item for the button.
button : |
a GtkButton |
use_stock : |
TRUE if the button should use a stock item
|
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 : |
a GtkButton |
Returns : | 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 : |
a GtkButton |
use_underline : |
TRUE if underlines in the text indicate mnemonics
|
void gtk_button_set_focus_on_click (GtkButton *button, gboolean focus_on_click);
Sets whether the button will grab focus when it is clicked with the mouse. Making mouse clicks not grab focus is useful in places like toolbars where you don't want the keyboard focus removed from the main area of the application.
button : |
a GtkButton |
focus_on_click : |
whether the button grabs focus when clicked with the mouse |
Since 2.4
gboolean gtk_button_get_focus_on_click (GtkButton *button);
Returns whether the button grabs focus when it is clicked with the mouse.
See gtk_button_set_focus_on_click()
.
button : |
a GtkButton |
Returns : | TRUE if the button grabs focus when it is clicked with
the mouse.
|
Since 2.4
void gtk_button_set_alignment (GtkButton *button, gfloat xalign, gfloat yalign);
Sets the alignment of the child. This property has no effect unless the child is a GtkMisc or a GtkAligment.
button : |
a GtkButton |
xalign : |
the horizontal position of the child, 0.0 is left aligned, 1.0 is right aligned |
yalign : |
the vertical position of the child, 0.0 is top aligned, 1.0 is bottom aligned |
Since 2.4
void gtk_button_get_alignment (GtkButton *button, gfloat *xalign, gfloat *yalign);
Gets the alignment of the child in the button.
button : |
a GtkButton |
xalign : |
return location for horizontal alignment |
yalign : |
return location for vertical alignment |
Since 2.4
void gtk_button_set_image (GtkButton *button, GtkWidget *image);
Set the image of button
to the given widget. Note that
it depends on the "gtk-button-images" setting whether the
image will be displayed or not, you don't have to call
gtk_widget_show()
on image
yourself.
button : |
a GtkButton |
image : |
a widget to set as the image for the button |
Since 2.6
GtkWidget* gtk_button_get_image (GtkButton *button);
Gets the widget that is currenty set as the image of button
.
This may have been explicitly set by gtk_button_set_image()
or constructed by gtk_button_new_from_stock()
.
Since 2.6
void gtk_button_set_image_position (GtkButton *button, GtkPositionType position);
Sets the position of the image relative to the text inside the button.
button : |
a GtkButton |
position : |
the position |
Since 2.10
GtkPositionType gtk_button_get_image_position (GtkButton *button);
Gets the position of the image relative to the text inside the button.
button : |
a GtkButton |
Returns : | the position |
Since 2.10
"focus-on-click"
property"focus-on-click" gboolean : Read / Write
Whether the button grabs focus when it is clicked with the mouse.
Default value: TRUE
"image"
property"image" GtkWidget* : Read / Write
Child widget to appear next to the button text.
"image-position"
property"image-position" GtkPositionType : Read / Write
The position of the image relative to the text inside the button.
Default value: GTK_POS_LEFT
Since 2.10
"label"
property"label" gchar* : Read / Write / Construct
Text of the label widget inside the button, if the button contains a label widget.
Default value: NULL
"relief"
property"relief" GtkReliefStyle : Read / Write
The border relief style.
Default value: GTK_RELIEF_NORMAL
"use-stock"
property"use-stock" gboolean : Read / Write / Construct
If set, the label is used to pick a stock item instead of being displayed.
Default value: FALSE
"use-underline"
property"use-underline" gboolean : Read / Write / Construct
If set, an underline in the text indicates the next character should be used for the mnemonic accelerator key.
Default value: FALSE
"xalign"
property"xalign" gfloat : Read / Write
If the child of the button is a GtkMisc or GtkAlignment, this property can be used to control it's horizontal alignment. 0.0 is left aligned, 1.0 is right aligned.
Allowed values: [0,1]
Default value: 0.5
Since 2.4
"yalign"
property"yalign" gfloat : Read / Write
If the child of the button is a GtkMisc or GtkAlignment, this property can be used to control it's vertical alignment. 0.0 is top aligned, 1.0 is bottom aligned.
Allowed values: [0,1]
Default value: 0.5
Since 2.4
"child-displacement-x"
style property"child-displacement-x" gint : Read
How far in the x direction to move the child when the button is depressed.
Default value: 0
"child-displacement-y"
style property"child-displacement-y" gint : Read
How far in the y direction to move the child when the button is depressed.
Default value: 0
"default-border"
style property"default-border" GtkBorder* : Read
Extra space to add for CAN_DEFAULT buttons.
"default-outside-border"
style property"default-outside-border" GtkBorder* : Read
Extra space to add for CAN_DEFAULT buttons that is always drawn outside the border.
"displace-focus"
style property"displace-focus" gboolean : Read
Whether the child_displacement_x/child_displacement_y properties should also affect the focus rectangle.
Default value: FALSE
Since 2.6
"image-spacing"
style property"image-spacing" gint : Read
Spacing in pixels between the image and label.
Allowed values: >= 0
Default value: 2
"inner-border"
style property"inner-border" GtkBorder* : Read
Sets the border between the button edges and child.
Since 2.10
"tree-view-separator-area"
style property"tree-view-separator-area" gint : Read
Specifies the amount of pixels to reserve for drawing a separator below the button. This is used to visually separate column headers from the tree view. The separator which will be drawn is exactly 1px thick. When 0, no separator will be drawn.
Allowed values: >= 0
Default value: 0
Since maemo 4.0
Stability Level Unstable
"activate"
signalvoid user_function (GtkButton *widget, gpointer user_data) : Run First / Action
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. |
"clicked"
signalvoid user_function (GtkButton *button, gpointer user_data) : Run First / Action
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. |
"enter"
signalvoid user_function (GtkButton *button, gpointer user_data) : Run First
Emitted when the pointer enters the button.
button : |
the object that received the signal |
user_data : |
user data set when the signal handler was connected. |
"leave"
signalvoid user_function (GtkButton *button, gpointer user_data) : Run First
Emitted when the pointer leaves the button.
button : |
the object that received the signal |
user_data : |
user data set when the signal handler was connected. |
"pressed"
signalvoid user_function (GtkButton *button, gpointer user_data) : Run First
Emitted when the button is pressed.
button : |
the object that received the signal |
user_data : |
user data set when the signal handler was connected. |