GtkInfoBar — Report important messages to the user
GtkWidget * | gtk_info_bar_new () |
GtkWidget * | gtk_info_bar_new_with_buttons () |
void | gtk_info_bar_add_action_widget () |
void | gtk_info_bar_remove_action_widget () |
GtkWidget * | gtk_info_bar_add_button () |
void | gtk_info_bar_add_buttons () |
void | gtk_info_bar_set_response_sensitive () |
void | gtk_info_bar_set_default_response () |
void | gtk_info_bar_response () |
void | gtk_info_bar_set_message_type () |
GtkMessageType | gtk_info_bar_get_message_type () |
gboolean | gtk_info_bar_get_show_close_button () |
void | gtk_info_bar_set_show_close_button () |
gboolean | gtk_info_bar_get_revealed () |
void | gtk_info_bar_set_revealed () |
void | gtk_info_bar_add_child () |
void | gtk_info_bar_remove_child () |
GtkMessageType | message-type | Read / Write / Construct |
gboolean | revealed | Read / Write |
gboolean | show-close-button | Read / Write / Construct |
GObject ╰── GInitiallyUnowned ╰── GtkWidget ╰── GtkInfoBar
GtkInfoBar implements GtkAccessible, GtkBuildable and GtkConstraintTarget.
#include <gtk/gtk.h>
GtkInfoBar is a widget that can be used to show messages to the user without showing a dialog. It is often temporarily shown at the top or bottom of a document. In contrast to GtkDialog, which has an action area at the bottom, GtkInfoBar has an action area at the side.
The API of GtkInfoBar is very similar to GtkDialog, allowing you to add buttons to the action area with gtk_info_bar_add_button()
or gtk_info_bar_new_with_buttons()
. The sensitivity of action widgets can be controlled with gtk_info_bar_set_response_sensitive()
.
To add widgets to the main content area of a GtkInfoBar, use gtk_info_bar_add_child()
.
Similar to GtkMessageDialog, the contents of a GtkInfoBar can by classified as error message, warning, informational message, etc, by using gtk_info_bar_set_message_type()
. GTK may use the message type to determine how the message is displayed.
A simple example for using a GtkInfoBar:
GtkWidget *message_label; GtkWidget *widget; GtkWidget *grid; GtkInfoBar *bar; // set up info bar widget = gtk_info_bar_new (); bar = GTK_INFO_BAR (widget); grid = gtk_grid_new (); message_label = gtk_label_new (""); gtk_info_bar_add_child (bar, message_label); gtk_info_bar_add_button (bar, _("_OK"), GTK_RESPONSE_OK); g_signal_connect (bar, "response", G_CALLBACK (gtk_widget_hide), NULL); gtk_grid_attach (GTK_GRID (grid), widget, 0, 2, 1, 1); // ... // show an error message gtk_label_set_text (GTK_LABEL (message_label), "An error occurred!"); gtk_info_bar_set_message_type (bar, GTK_MESSAGE_ERROR); gtk_widget_show (bar);
The GtkInfoBar implementation of the GtkBuildable interface exposes the content area and action area as internal children with the names “content_area” and “action_area”.
GtkInfoBar supports a custom <action-widgets> element, which can contain multiple <action-widget> elements. The “response” attribute specifies a numeric response, and the content of the element is the id of widget (which should be a child of the dialogs action_area
).
GtkInfoBar has a single CSS node with name infobar. The node may get one of the style classes .info, .warning, .error or .question, depending on the message type. If the info bar shows a close button, that button will have the .close style class applied.
GtkWidget *
gtk_info_bar_new (void
);
Creates a new GtkInfoBar object.
a new GtkInfoBar object
GtkWidget * gtk_info_bar_new_with_buttons (const char *first_button_text
,...
);
Creates a new GtkInfoBar with buttons. Button text/response ID pairs should be listed, with a NULL
pointer ending the list. A response ID can be any positive number, or one of the values in the GtkResponseType enumeration. If the user clicks one of these dialog buttons, GtkInfoBar will emit the “response” signal with the corresponding response ID.
first_button_text | ext to go in first button, or | [allow-none] |
... | response ID for first button, then additional buttons, ending with |
a new GtkInfoBar
void gtk_info_bar_add_action_widget (GtkInfoBar *info_bar
,GtkWidget *child
,int response_id
);
Add an activatable widget to the action area of a GtkInfoBar, connecting a signal handler that will emit the “response” signal on the message area when the widget is activated. The widget is appended to the end of the message areas action area.
info_bar | ||
child | an activatable widget | |
response_id | response ID for |
void gtk_info_bar_remove_action_widget (GtkInfoBar *info_bar
,GtkWidget *widget
);
Removes a widget from the action area of info_bar
, after it been put there by a call to gtk_info_bar_add_action_widget()
or gtk_info_bar_add_button()
.
info_bar | ||
widget | an action widget to remove |
GtkWidget * gtk_info_bar_add_button (GtkInfoBar *info_bar
,const char *button_text
,int response_id
);
Adds a button with the given text and sets things up so that clicking the button will emit the “response” signal with the given response_id. The button is appended to the end of the info bars's action area. The button widget is returned, but usually you don't need it.
info_bar | ||
button_text | text of button | |
response_id | response ID for the button |
void gtk_info_bar_add_buttons (GtkInfoBar *info_bar
,const char *first_button_text
,...
);
Adds more buttons, same as calling gtk_info_bar_add_button()
repeatedly. The variable argument list should be NULL
-terminated as with gtk_info_bar_new_with_buttons()
. Each button must have both text and response ID.
info_bar | ||
first_button_text | button text | |
... | response ID for first button, then more text-response_id pairs, ending with |
void gtk_info_bar_set_response_sensitive (GtkInfoBar *info_bar
,int response_id
,gboolean setting
);
Calls gtk_widget_set_sensitive (widget, setting) for each widget in the info bars’s action area with the given response_id. A convenient way to sensitize/desensitize dialog buttons.
info_bar | ||
response_id | a response ID | |
setting | TRUE for sensitive |
void gtk_info_bar_set_default_response (GtkInfoBar *info_bar
,int response_id
);
Sets the last widget in the info bar’s action area with the given response_id as the default widget for the dialog. Pressing “Enter” normally activates the default widget.
Note that this function currently requires info_bar
to be added to a widget hierarchy.
info_bar | ||
response_id | a response ID |
void gtk_info_bar_response (GtkInfoBar *info_bar
,int response_id
);
Emits the “response” signal with the given response_id
.
info_bar | ||
response_id | a response ID |
void gtk_info_bar_set_message_type (GtkInfoBar *info_bar
,GtkMessageType message_type
);
Sets the message type of the message area.
GTK uses this type to determine how the message is displayed.
info_bar | ||
message_type |
GtkMessageType
gtk_info_bar_get_message_type (GtkInfoBar *info_bar
);
Returns the message type of the message area.
info_bar |
the message type of the message area.
gboolean
gtk_info_bar_get_show_close_button (GtkInfoBar *info_bar
);
Returns whether the widget will display a standard close button.
info_bar |
TRUE
if the widget displays standard close button
void gtk_info_bar_set_show_close_button (GtkInfoBar *info_bar
,gboolean setting
);
If true, a standard close button is shown. When clicked it emits the response GTK_RESPONSE_CLOSE
.
info_bar | ||
setting |
|
gboolean
gtk_info_bar_get_revealed (GtkInfoBar *info_bar
);
Returns whether the info bar is currently revealed.
info_bar |
the current value of the “revealed” property
void gtk_info_bar_set_revealed (GtkInfoBar *info_bar
,gboolean revealed
);
Sets the “revealed” property to revealed
. Changing this will make info_bar
reveal (TRUE
) or conceal (FALSE
) itself via a sliding transition.
Note: this does not show or hide info_bar
in the “visible” sense, so revealing has no effect if “visible” is FALSE
.
info_bar | ||
revealed | The new value of the property |
void gtk_info_bar_add_child (GtkInfoBar *info_bar
,GtkWidget *widget
);
Adds a widget to the content area of the info bar.
info_bar | ||
widget | the child to be added |
void gtk_info_bar_remove_child (GtkInfoBar *info_bar
,GtkWidget *widget
);
Removes a widget from the content area of the info bar, after it has been added with gtk_info_bar_add_child()
.
info_bar | ||
widget | a child that has been added to the content area |
typedef struct _GtkInfoBar GtkInfoBar;
“message-type”
property“message-type” GtkMessageType
The type of the message.
The type may be used to determine the appearance of the info bar.
Owner: GtkInfoBar
Flags: Read / Write / Construct
Default value: GTK_MESSAGE_INFO
“revealed”
property“revealed” gboolean
Controls whether the info bar shows its contents or not.
Owner: GtkInfoBar
Flags: Read / Write
Default value: TRUE
“show-close-button”
property“show-close-button” gboolean
Whether to include a standard close button.
Owner: GtkInfoBar
Flags: Read / Write / Construct
Default value: FALSE
“close”
signalvoid user_function (GtkInfoBar *infobar, gpointer user_data)
The ::close signal is a keybinding signal which gets emitted when the user uses a keybinding to dismiss the info bar.
The default binding for this signal is the Escape key.
user_data | user data set when the signal handler was connected. |
Flags: Action
“response”
signalvoid user_function (GtkInfoBar *info_bar, int response_id, gpointer user_data)
Emitted when an action widget is clicked or the application programmer calls gtk_info_bar_response()
. The response_id
depends on which action widget was clicked.
info_bar | the object on which the signal is emitted | |
response_id | the response ID | |
user_data | user data set when the signal handler was connected. |
Flags: Run Last
© 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/GtkInfoBar.html