CtkButton

CtkButton — A widget that emits a signal when clicked on

Functions

Properties

gboolean always-show-image Read / Write / Construct
CtkWidget * image Read / Write
CtkPositionType image-position Read / Write
char * label Read / Write / Construct
CtkReliefStyle relief Read / Write
gboolean use-stock Read / Write / Construct
gboolean use-underline Read / Write / Construct
float xalign Read / Write
float yalign Read / Write

Signals

void activate Action
void clicked Action
void enter Run First
void leave Run First
void pressed Run First
void released Run First

Types and Values

struct CtkButton
struct CtkButtonClass

Object Hierarchy

    GObject
    ╰── GInitiallyUnowned
        ╰── CtkWidget
            ╰── CtkContainer
                ╰── CtkBin
                    ╰── CtkButton
                        ├── CtkToggleButton
                        ├── CtkColorButton
                        ├── CtkFontButton
                        ├── CtkLinkButton
                        ├── CtkLockButton
                        ├── CtkModelButton
                        ╰── CtkScaleButton

Implemented Interfaces

CtkButton implements AtkImplementorIface, CtkBuildable, CtkActionable and CtkActivatable.

Includes

#include <ctk/ctk.h>

Description

The CtkButton 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 CtkButton widget can hold any valid child widget. That is, it can hold almost any other standard CtkWidget. The most commonly used child is the CtkLabel.

CSS nodes

CtkButton 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 CtkButton include .suggested-action and .destructive-action. In special cases, buttons can be made round by adding the .circular style class.

Button-like widgets like CtkToggleButton, CtkMenuButton, CtkVolumeButton, CtkLockButton, CtkColorButton, CtkFontButton or CtkFileChooserButton use style classes such as .toggle, .popup, .scale, .lock, .color, .font, .file to differentiate themselves from a plain CtkButton.

Functions

ctk_button_new ()

CtkWidget *
ctk_button_new (void);

Creates a new CtkButton widget. To add a child widget to the button, use ctk_container_add().

Returns

The newly created CtkButton widget.


ctk_button_new_with_label ()

CtkWidget *
ctk_button_new_with_label (const gchar *label);

Creates a CtkButton widget with a CtkLabel child containing the given text.

Parameters

label

The text you want the CtkLabel to hold.

 

Returns

The newly created CtkButton widget.


ctk_button_new_with_mnemonic ()

CtkWidget *
ctk_button_new_with_mnemonic (const gchar *label);

Creates a new CtkButton 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.

Parameters

label

The text of the button, with an underscore in front of the mnemonic character

 

Returns

a new CtkButton


ctk_button_new_from_icon_name ()

CtkWidget *
ctk_button_new_from_icon_name (const gchar *icon_name,
                               CtkIconSize 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.

This function is a convenience wrapper around ctk_button_new() and ctk_button_set_image().

Parameters

icon_name

an icon name or NULL.

[nullable]

size

an icon size (CtkIconSize).

[type int]

Returns

a new CtkButton displaying the themed icon

Since: 3.10


ctk_button_new_from_stock ()

CtkWidget *
ctk_button_new_from_stock (const gchar *stock_id);

Creates a new CtkButton containing the image and text from a stock item. Some stock ids have preprocessor macros like CTK_STOCK_OK and CTK_STOCK_APPLY.

If stock_id is unknown, then it will be treated as a mnemonic label (as for ctk_button_new_with_mnemonic()).

Parameters

stock_id

the name of the stock item

 

Returns

a new CtkButton


ctk_button_pressed ()

void
ctk_button_pressed (CtkButton *button);

Emits a “pressed” signal to the given CtkButton.

Parameters

button

The CtkButton you want to send the signal to.

 

ctk_button_released ()

void
ctk_button_released (CtkButton *button);

Emits a “released” signal to the given CtkButton.

Parameters

button

The CtkButton you want to send the signal to.

 

ctk_button_clicked ()

void
ctk_button_clicked (CtkButton *button);

Emits a “clicked” signal to the given CtkButton.

Parameters

button

The CtkButton you want to send the signal to.

 

ctk_button_enter ()

void
ctk_button_enter (CtkButton *button);

ctk_button_enter has been deprecated since version 2.20 and should not be used in newly-written code.

Use the “enter-notify-event” signal.

Emits a “enter” signal to the given CtkButton.

Parameters

button

The CtkButton you want to send the signal to.

 

ctk_button_leave ()

void
ctk_button_leave (CtkButton *button);

ctk_button_leave has been deprecated since version 2.20 and should not be used in newly-written code.

Use the “leave-notify-event” signal.

Emits a “leave” signal to the given CtkButton.

Parameters

button

The CtkButton you want to send the signal to.

 

ctk_button_set_relief ()

void
ctk_button_set_relief (CtkButton *button,
                       CtkReliefStyle relief);

Sets the relief style of the edges of the given CtkButton widget. Two styles exist, CTK_RELIEF_NORMAL and CTK_RELIEF_NONE. The default style is, as one can guess, CTK_RELIEF_NORMAL. The deprecated value CTK_RELIEF_HALF behaves the same as CTK_RELIEF_NORMAL.

Parameters

button

The CtkButton you want to set relief styles of

 

relief

The CtkReliefStyle as described above

 

ctk_button_get_relief ()

CtkReliefStyle
ctk_button_get_relief (CtkButton *button);

Returns the current relief style of the given CtkButton.

Parameters

button

The CtkButton you want the CtkReliefStyle from.

 

Returns

The current CtkReliefStyle


ctk_button_get_label ()

const gchar *
ctk_button_get_label (CtkButton *button);

Fetches the text from the label of the button, as set by ctk_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 ctk_button_new() to use as a container.

Parameters

button

a CtkButton

 

Returns

The text of the label widget. This string is owned by the widget and must not be modified or freed.


ctk_button_set_label ()

void
ctk_button_set_label (CtkButton *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 ctk_button_set_use_stock() is used.

This will also clear any previously set labels.

Parameters

button

a CtkButton

 

label

a string

 

ctk_button_get_use_stock ()

gboolean
ctk_button_get_use_stock (CtkButton *button);

ctk_button_get_use_stock has been deprecated since version 3.10 and should not be used in newly-written code.

Returns whether the button label is a stock item.

Parameters

button

a CtkButton

 

Returns

TRUE if the button label is used to select a stock item instead of being used directly as the label text.


ctk_button_set_use_stock ()

void
ctk_button_set_use_stock (CtkButton *button,
                          gboolean use_stock);

ctk_button_set_use_stock has been deprecated since version 3.10 and should not be used in newly-written code.

If TRUE, the label set on the button is used as a stock id to select the stock item for the button.

Parameters

button

a CtkButton

 

use_stock

TRUE if the button should use a stock item

 

ctk_button_get_use_underline ()

gboolean
ctk_button_get_use_underline (CtkButton *button);

Returns whether an embedded underline in the button label indicates a mnemonic. See ctk_button_set_use_underline().

Parameters

button

a CtkButton

 

Returns

TRUE if an embedded underline in the button label indicates the mnemonic accelerator keys.


ctk_button_set_use_underline ()

void
ctk_button_set_use_underline (CtkButton *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.

Parameters

button

a CtkButton

 

use_underline

TRUE if underlines in the text indicate mnemonics

 

ctk_button_set_focus_on_click ()

void
ctk_button_set_focus_on_click (CtkButton *button,
                               gboolean focus_on_click);

ctk_button_set_focus_on_click has been deprecated since version 3.20 and should not be used in newly-written code.

Use ctk_widget_set_focus_on_click() instead

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.

Parameters

button

a CtkButton

 

focus_on_click

whether the button grabs focus when clicked with the mouse

 

Since: 2.4


ctk_button_get_focus_on_click ()

gboolean
ctk_button_get_focus_on_click (CtkButton *button);

ctk_button_get_focus_on_click has been deprecated since version 3.20 and should not be used in newly-written code.

Use ctk_widget_get_focus_on_click() instead

Returns whether the button grabs focus when it is clicked with the mouse. See ctk_button_set_focus_on_click().

Parameters

button

a CtkButton

 

Returns

TRUE if the button grabs focus when it is clicked with the mouse.

Since: 2.4


ctk_button_set_alignment ()

void
ctk_button_set_alignment (CtkButton *button,
                          gfloat xalign,
                          gfloat yalign);

ctk_button_set_alignment has been deprecated since version 3.14 and should not be used in newly-written code.

Access the child widget directly if you need to control its alignment.

Sets the alignment of the child. This property has no effect unless the child is a CtkMisc or a CtkAlignment.

Parameters

button

a CtkButton

 

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


ctk_button_get_alignment ()

void
ctk_button_get_alignment (CtkButton *button,
                          gfloat *xalign,
                          gfloat *yalign);

ctk_button_get_alignment has been deprecated since version 3.14 and should not be used in newly-written code.

Access the child widget directly if you need to control its alignment.

Gets the alignment of the child in the button.

Parameters

button

a CtkButton

 

xalign

return location for horizontal alignment.

[out]

yalign

return location for vertical alignment.

[out]

Since: 2.4


ctk_button_set_image ()

void
ctk_button_set_image (CtkButton *button,
                      CtkWidget *image);

Set the image of button to the given widget. The image will be displayed if the label text is NULL or if “always-show-image” is TRUE. You don’t have to call ctk_widget_show() on image yourself.

Parameters

button

a CtkButton

 

image

a widget to set as the image for the button, or NULL to unset.

[nullable]

Since: 2.6


ctk_button_get_image ()

CtkWidget *
ctk_button_get_image (CtkButton *button);

Gets the widget that is currenty set as the image of button . This may have been explicitly set by ctk_button_set_image() or constructed by ctk_button_new_from_stock().

Parameters

button

a CtkButton

 

Returns

a CtkWidget or NULL in case there is no image.

[nullable][transfer none]

Since: 2.6


ctk_button_set_image_position ()

void
ctk_button_set_image_position (CtkButton *button,
                               CtkPositionType position);

Sets the position of the image relative to the text inside the button.

Parameters

button

a CtkButton

 

position

the position

 

Since: 2.10


ctk_button_get_image_position ()

CtkPositionType
ctk_button_get_image_position (CtkButton *button);

Gets the position of the image relative to the text inside the button.

Parameters

button

a CtkButton

 

Returns

the position

Since: 2.10


ctk_button_set_always_show_image ()

void
ctk_button_set_always_show_image (CtkButton *button,
                                  gboolean always_show);

If TRUE, the button will ignore the “ctk-button-images” setting and always show the image, if available.

Use this property if the button would be useless or hard to use without the image.

Parameters

button

a CtkButton

 

always_show

TRUE if the menuitem should always show the image

 

Since: 3.6


ctk_button_get_always_show_image ()

gboolean
ctk_button_get_always_show_image (CtkButton *button);

Returns whether the button will ignore the “ctk-button-images” setting and always show the image, if available.

Parameters

button

a CtkButton

 

Returns

TRUE if the button will always show the image

Since: 3.6


ctk_button_get_event_window ()

CdkWindow *
ctk_button_get_event_window (CtkButton *button);

Returns the button’s event window if it is realized, NULL otherwise. This function should be rarely needed.

Parameters

button

a CtkButton

 

Returns

button ’s event window.

[transfer none]

Since: 2.22

Types and Values

struct CtkButton

struct CtkButton;

struct CtkButtonClass

struct CtkButtonClass {
  CtkBinClass        parent_class;

  void (* pressed)  (CtkButton *button);
  void (* released) (CtkButton *button);
  void (* clicked)  (CtkButton *button);
  void (* enter)    (CtkButton *button);
  void (* leave)    (CtkButton *button);
  void (* activate) (CtkButton *button);
};

Members

pressed ()

Signal emitted when the button is pressed.

 

released ()

Signal emitted when the button is released.

 

clicked ()

Signal emitted when the button has been activated (pressed and released).

 

enter ()

Signal emitted when the pointer enters the button. Deprecated: 2.8.

 

leave ()

Signal emitted when the pointer leaves the button. Deprecated: 2.8.

 

activate ()

Signal that causes the button to animate press then release. Applications should never connect to this signal, but use the clicked signal.

 

Property Details

The “always-show-image” property

  “always-show-image”        gboolean

If TRUE, the button will ignore the “ctk-button-images” setting and always show the image, if available.

Use this property if the button would be useless or hard to use without the image.

Owner: CtkButton

Flags: Read / Write / Construct

Default value: FALSE

Since: 3.6


The “image” property

  “image”                    CtkWidget *

The child widget to appear next to the button text.

Owner: CtkButton

Flags: Read / Write

Since: 2.6


The “image-position” property

  “image-position”           CtkPositionType

The position of the image relative to the text inside the button.

Owner: CtkButton

Flags: Read / Write

Default value: CTK_POS_LEFT

Since: 2.10


The “label” property

  “label”                    char *

Text of the label widget inside the button, if the button contains a label widget.

Owner: CtkButton

Flags: Read / Write / Construct

Default value: NULL


The “relief” property

  “relief”                   CtkReliefStyle

The border relief style.

Owner: CtkButton

Flags: Read / Write

Default value: CTK_RELIEF_NORMAL


The “use-stock” property

  “use-stock”                gboolean

If set, the label is used to pick a stock item instead of being displayed.

CtkButton:use-stock has been deprecated since version 3.10 and should not be used in newly-written code.

Owner: CtkButton

Flags: Read / Write / Construct

Default value: FALSE


The “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: CtkButton

Flags: Read / Write / Construct

Default value: FALSE


The “xalign” property

  “xalign”                   float

If the child of the button is a CtkMisc or CtkAlignment, this property can be used to control its horizontal alignment. 0.0 is left aligned, 1.0 is right aligned.

CtkButton:xalign has been deprecated since version 3.14 and should not be used in newly-written code.

Access the child widget directly if you need to control its alignment.

Owner: CtkButton

Flags: Read / Write

Allowed values: [0,1]

Default value: 0.5

Since: 2.4


The “yalign” property

  “yalign”                   float

If the child of the button is a CtkMisc or CtkAlignment, this property can be used to control its vertical alignment. 0.0 is top aligned, 1.0 is bottom aligned.

CtkButton:yalign has been deprecated since version 3.14 and should not be used in newly-written code.

Access the child widget directly if you need to control its alignment.

Owner: CtkButton

Flags: Read / Write

Allowed values: [0,1]

Default value: 0.5

Since: 2.4

Signal Details

The “activate” signal

void
user_function (CtkButton *widget,
               gpointer   user_data)

The ::activate signal on CtkButton 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.

Parameters

widget

the object which received the signal.

 

user_data

user data set when the signal handler was connected.

 

Flags: Action


The “clicked” signal

void
user_function (CtkButton *button,
               gpointer   user_data)

Emitted when the button has been activated (pressed and released).

Parameters

button

the object that received the signal

 

user_data

user data set when the signal handler was connected.

 

Flags: Action


The “enter” signal

void
user_function (CtkButton *button,
               gpointer   user_data)

Emitted when the pointer enters the button.

CtkButton::enter has been deprecated since version 2.8 and should not be used in newly-written code.

Use the “enter-notify-event” signal.

Parameters

button

the object that received the signal

 

user_data

user data set when the signal handler was connected.

 

Flags: Run First


The “leave” signal

void
user_function (CtkButton *button,
               gpointer   user_data)

Emitted when the pointer leaves the button.

CtkButton::leave has been deprecated since version 2.8 and should not be used in newly-written code.

Use the “leave-notify-event” signal.

Parameters

button

the object that received the signal

 

user_data

user data set when the signal handler was connected.

 

Flags: Run First


The “pressed” signal

void
user_function (CtkButton *button,
               gpointer   user_data)

Emitted when the button is pressed.

Parameters

button

the object that received the signal

 

user_data

user data set when the signal handler was connected.

 

Flags: Run First


The “released” signal

void
user_function (CtkButton *button,
               gpointer   user_data)

Emitted when the button is released.

Parameters

button

the object that received the signal

 

user_data

user data set when the signal handler was connected.

 

Flags: Run First