Whether the widget is double buffered.
Whether to expand in both directions. Setting this sets both #GtkWidget:hexpand and #GtkWidget:vexpand
Whether the widget should grab focus when it is clicked with the mouse.
This property is only relevant for widgets that can take focus.
Before 3.20, several widgets (GtkButton, GtkFileChooserButton, GtkComboBox) implemented this property individually.
How to distribute horizontal space if widget gets extra space, see #GtkAlign
Enables or disables the emission of #GtkWidget::query-tooltip on widget
.
A value of %TRUE indicates that widget
can have a tooltip, in this case
the widget will be queried using #GtkWidget::query-tooltip to determine
whether it will provide a tooltip or not.
Note that setting this property to %TRUE for the first time will change the event masks of the GdkWindows of this widget to include leave-notify and motion-notify events. This cannot and will not be undone when the property is set to %FALSE again.
Whether to expand horizontally. See gtk_widget_set_hexpand().
Whether to use the #GtkWidget:hexpand property. See gtk_widget_get_hexpand_set().
Sets all four sides' margin at once. If read, returns max margin on any side.
Margin on bottom side of widget.
This property adds margin outside of the widget's normal size request, the margin will be added in addition to the size from gtk_widget_set_size_request() for example.
Margin on end of widget, horizontally. This property supports left-to-right and right-to-left text directions.
This property adds margin outside of the widget's normal size request, the margin will be added in addition to the size from gtk_widget_set_size_request() for example.
Margin on left side of widget.
This property adds margin outside of the widget's normal size request, the margin will be added in addition to the size from gtk_widget_set_size_request() for example.
Margin on right side of widget.
This property adds margin outside of the widget's normal size request, the margin will be added in addition to the size from gtk_widget_set_size_request() for example.
Margin on start of widget, horizontally. This property supports left-to-right and right-to-left text directions.
This property adds margin outside of the widget's normal size request, the margin will be added in addition to the size from gtk_widget_set_size_request() for example.
Margin on top side of widget.
This property adds margin outside of the widget's normal size request, the margin will be added in addition to the size from gtk_widget_set_size_request() for example.
The requested opacity of the widget. See gtk_widget_set_opacity() for more details about window opacity.
Before 3.8 this was only available in GtkWindow
The scale factor of the widget. See gtk_widget_get_scale_factor() for more details about widget scaling.
The style of the widget, which contains information about how it will look (colors, etc).
Sets the text of tooltip to be the given string, which is marked up with the [Pango text markup language][PangoMarkupFormat]. Also see gtk_tooltip_set_markup().
This is a convenience property which will take care of getting the tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip will automatically be set to %TRUE and there will be taken care of #GtkWidget::query-tooltip in the default signal handler.
Note that if both #GtkWidget:tooltip-text and #GtkWidget:tooltip-markup are set, the last one wins.
Sets the text of tooltip to be the given string.
Also see gtk_tooltip_set_text().
This is a convenience property which will take care of getting the tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip will automatically be set to %TRUE and there will be taken care of #GtkWidget::query-tooltip in the default signal handler.
Note that if both #GtkWidget:tooltip-text and #GtkWidget:tooltip-markup are set, the last one wins.
How to distribute vertical space if widget gets extra space, see #GtkAlign
Whether to expand vertically. See gtk_widget_set_vexpand().
Whether to use the #GtkWidget:vexpand property. See gtk_widget_get_vexpand_set().
The widget's window if it is realized, %NULL otherwise.
For widgets that can be “activated” (buttons, menu items, etc.)
this function activates them. Activation is what happens when you
press Enter on a widget during key navigation. If widget
isn't
activatable, the function returns %FALSE.
Installs an accelerator for this widget
in accel_group
that causes
accel_signal
to be emitted if the accelerator is activated.
The accel_group
needs to be added to the widget’s toplevel via
gtk_window_add_accel_group(), and the signal must be of type %G_SIGNAL_ACTION.
Accelerators added through this function are not user changeable during
runtime. If you want to support accelerators that can be changed by the
user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
gtk_menu_item_set_accel_path() instead.
widget signal to emit on accelerator activation
accel group for this widget, added to its toplevel
GDK keyval of the accelerator
modifier key combination of the accelerator
flag accelerators, e.g. %GTK_ACCEL_VISIBLE
Adds the events in the bitfield events
to the event mask for
widget
. See gtk_widget_set_events() and the
[input handling overview][event-masks] for details.
an event mask, see #GdkEventMask
Adds a widget to the list of mnemonic labels for this widget. (See gtk_widget_list_mnemonic_labels()). Note the list of mnemonic labels for the widget is cleared when the widget is destroyed, so the caller must make sure to update its internal state at this point as well, by using a connection to the #GtkWidget::destroy signal or a weak notifier.
Queues an animation frame update and adds a callback to be called before each frame. Until the tick callback is removed, it will be called frequently (usually at the frame rate of the output device or as quickly as the application can be repainted, whichever is slower). For this reason, is most suitable for handling graphics that change every frame or every few frames. The tick callback does not automatically imply a relayout or repaint. If you want a repaint or relayout, and aren’t changing widget properties that would trigger that (for example, changing the text of a #GtkLabel), then you will have to call gtk_widget_queue_resize() or gtk_widget_queue_draw_area() yourself.
gdk_frame_clock_get_frame_time() should generally be used for timing continuous animations and gdk_frame_timings_get_predicted_presentation_time() if you are trying to display isolated frames at particular times.
This is a more convenient alternative to connecting directly to the #GdkFrameClock::update signal of #GdkFrameClock, since you don't have to worry about when a #GdkFrameClock is assigned to a widget.
function to call for updating animations
Creates a binding between source_property
on source
and target_property
on target
.
Whenever the source_property
is changed the target_property
is
updated using the same value. For instance:
g_object_bind_property (action, "active", widget, "sensitive", 0);
Will result in the "sensitive" property of the widget #GObject instance to be updated with the same value of the "active" property of the action #GObject instance.
If flags
contains %G_BINDING_BIDIRECTIONAL then the binding will be mutual:
if target_property
on target
changes then the source_property
on source
will be updated as well.
The binding will automatically be removed when either the source
or the
target
instances are finalized. To remove the binding without affecting the
source
and the target
you can just call g_object_unref() on the returned
#GBinding instance.
Removing the binding by calling g_object_unref() on it must only be done if
the binding, source
and target
are only used from a single thread and it
is clear that both source
and target
outlive the binding. Especially it
is not safe to rely on this if the binding, source
or target
can be
finalized from different threads. Keep another reference to the binding and
use g_binding_unbind() instead to be on the safe side.
A #GObject can have multiple bindings.
the property on source
to bind
the target #GObject
the property on target
to bind
flags to pass to #GBinding
Creates a binding between source_property
on source
and target_property
on target,
allowing you to set the transformation functions to be used by
the binding.
This function is the language bindings friendly version of g_object_bind_property_full(), using #GClosures instead of function pointers.
the property on source
to bind
the target #GObject
the property on target
to bind
flags to pass to #GBinding
a #GClosure wrapping the transformation function from the source
to the target,
or %NULL to use the default
a #GClosure wrapping the transformation function from the target
to the source,
or %NULL to use the default
Determines whether an accelerator that activates the signal
identified by signal_id
can currently be activated.
This is done by emitting the #GtkWidget::can-activate-accel
signal on widget;
if the signal isn’t overridden by a
handler or in a derived widget, then the default check is
that the widget must be sensitive, and the widget and all
its ancestors mapped.
the ID of a signal installed on widget
This function is used by custom widget implementations; if you're writing an app, you’d use gtk_widget_grab_focus() to move the focus to a particular widget, and gtk_container_set_focus_chain() to change the focus tab order. So you may want to investigate those functions instead.
gtk_widget_child_focus() is called by containers as the user moves
around the window using keyboard shortcuts. direction
indicates
what kind of motion is taking place (up, down, left, right, tab
forward, tab backward). gtk_widget_child_focus() emits the
#GtkWidget::focus signal; widgets override the default handler
for this signal in order to implement appropriate focus behavior.
The default ::focus handler for a widget should return %TRUE if
moving in direction
left the focus on a focusable location inside
that widget, and %FALSE if moving in direction
moved the focus
outside the widget. If returning %TRUE, widgets normally
call gtk_widget_grab_focus() to place the focus accordingly;
if returning %FALSE, they don’t modify the current focus location.
direction of focus movement
Emits a #GtkWidget::child-notify signal for the
[child property][child-properties] child_property
on widget
.
This is the analogue of g_object_notify() for child properties.
Also see gtk_container_child_notify().
the name of a child property installed on the class of widget’
s parent
Same as gtk_widget_path(), but always uses the name of a widget’s type, never uses a custom name set with gtk_widget_set_name().
Computes whether a container should give this widget extra space when possible. Containers should check this, rather than looking at gtk_widget_get_hexpand() or gtk_widget_get_vexpand().
This function already checks whether the widget is visible, so visibility does not need to be checked separately. Non-visible widgets are not expanded.
The computed expand value uses either the expand setting explicitly set on the widget itself, or, if none has been explicitly set, the widget may expand if some of its children do.
expand direction
Creates a new #PangoLayout with the appropriate font map, font description, and base direction for drawing text for this widget.
If you keep a #PangoLayout created in this way around, you need to re-create it when the widget #PangoContext is replaced. This can be tracked by using the #GtkWidget::screen-changed signal on the widget.
text to set on the layout (can be %NULL)
This is similar to gtk_buildable_parser_finished() but is
called once for each custom tag handled by the buildable
.
a #GtkBuilder
child object or %NULL for non-child tags
the name of the tag
user data created in custom_tag_start
This is called at the end of each custom element handled by the buildable.
#GtkBuilder used to construct this object
child object or %NULL for non-child tags
name of tag
user data that will be passed in to parser functions
This is called for each unknown element under <child>
.
a #GtkBuilder used to construct this object
child object or %NULL for non-child tags
name of tag
Destroys a widget.
When a widget is destroyed all references it holds on other objects will be released:
It's expected that all references held on the widget will also
be released; you should connect to the #GtkWidget::destroy signal
if you hold a reference to widget
and you wish to remove it when
this function is called. It is not necessary to do so if you are
implementing a #GtkContainer, as you'll be able to use the
#GtkContainerClass.remove() virtual function for that.
It's important to notice that gtk_widget_destroy() will only cause
the widget
to be finalized if no additional references, acquired
using g_object_ref(), are held on it. In case additional references
are in place, the widget
will be in an "inert" state after calling
this function; widget
will still point to valid memory, allowing you
to release the references you hold, but you may not query the widget's
own state.
You should typically call this function on top level widgets, and rarely on child widgets.
See also: gtk_container_remove()
This function sets *widget_pointer
to %NULL if widget_pointer
!=
%NULL. It’s intended to be used as a callback connected to the
“destroy” signal of a widget. You connect gtk_widget_destroyed()
as a signal handler, and pass the address of your widget variable
as user data. Then when the widget is destroyed, the variable will
be set to %NULL. Useful for example to avoid multiple copies
of the same dialog.
This function is equivalent to gtk_drag_begin_with_coordinates(), passing -1, -1 as coordinates.
The targets (data formats) in which the source can provide the data
A bitmask of the allowed drag actions for this drag
The button the user clicked to start the drag
The event that triggered the start of the drag, or %NULL if none can be obtained.
Initiates a drag on the source side. The function only needs to be used when the application is starting drags itself, and is not needed when gtk_drag_source_set() is used.
The event
is used to retrieve the timestamp that will be used internally to
grab the pointer. If event
is %NULL, then %GDK_CURRENT_TIME will be used.
However, you should try to pass a real event in all cases, since that can be
used to get information about the drag.
Generally there are three cases when you want to start a drag by hand by calling this function:
During a #GtkWidget::button-press-event handler, if you want to start a drag
immediately when the user presses the mouse button. Pass the event
that you have in your #GtkWidget::button-press-event handler.
During a #GtkWidget::motion-notify-event handler, if you want to start a drag
when the mouse moves past a certain threshold distance after a button-press.
Pass the event
that you have in your #GtkWidget::motion-notify-event handler.
During a timeout handler, if you want to start a drag after the mouse button is held down for some time. Try to save the last event that you got from the mouse, using gdk_event_copy(), and pass it to this function (remember to free the event with gdk_event_free() when you are done). If you really cannot pass a real event, pass %NULL instead.
The targets (data formats) in which the source can provide the data
A bitmask of the allowed drag actions for this drag
The button the user clicked to start the drag
The event that triggered the start of the drag, or %NULL if none can be obtained.
The initial x coordinate to start dragging from, in the coordinate space of widget
. If -1 is passed, the coordinates are retrieved from event
or the current pointer position
The initial y coordinate to start dragging from, in the coordinate space of widget
. If -1 is passed, the coordinates are retrieved from event
or the current pointer position
Checks to see if a mouse drag starting at (start_x,
start_y)
and ending
at (current_x,
current_y)
has passed the GTK+ drag threshold, and thus
should trigger the beginning of a drag-and-drop operation.
X coordinate of start of drag
Y coordinate of start of drag
current X coordinate
current Y coordinate
Add the image targets supported by #GtkSelectionData to
the target list of the drag destination. The targets
are added with info
= 0. If you need another value,
use gtk_target_list_add_image_targets() and
gtk_drag_dest_set_target_list().
Add the text targets supported by #GtkSelectionData to
the target list of the drag destination. The targets
are added with info
= 0. If you need another value,
use gtk_target_list_add_text_targets() and
gtk_drag_dest_set_target_list().
Add the URI targets supported by #GtkSelectionData to
the target list of the drag destination. The targets
are added with info
= 0. If you need another value,
use gtk_target_list_add_uri_targets() and
gtk_drag_dest_set_target_list().
Looks for a match between the supported targets of context
and the
dest_target_list,
returning the first matching target, otherwise
returning %GDK_NONE. dest_target_list
should usually be the return
value from gtk_drag_dest_get_target_list(), but some widgets may
have different valid targets for different parts of the widget; in
that case, they will have to implement a drag_motion handler that
passes the correct target list to this function.
drag context
list of droppable targets, or %NULL to use gtk_drag_dest_get_target_list (widget)
.
Returns the list of targets this widget can accept from drag-and-drop.
Returns whether the widget has been configured to always emit #GtkWidget::drag-motion signals.
Sets a widget as a potential drop destination, and adds default behaviors.
The default behaviors listed in flags
have an effect similar
to installing default handlers for the widget’s drag-and-drop signals
(#GtkWidget::drag-motion, #GtkWidget::drag-drop, ...). They all exist
for convenience. When passing #GTK_DEST_DEFAULT_ALL for instance it is
sufficient to connect to the widget’s #GtkWidget::drag-data-received
signal to get primitive, but consistent drag-and-drop support.
Things become more complicated when you try to preview the dragged data,
as described in the documentation for #GtkWidget::drag-motion. The default
behaviors described by flags
make some assumptions, that can conflict
with your own signal handlers. For instance #GTK_DEST_DEFAULT_DROP causes
invokations of gdk_drag_status() in the context of #GtkWidget::drag-motion,
and invokations of gtk_drag_finish() in #GtkWidget::drag-data-received.
Especially the later is dramatic, when your own #GtkWidget::drag-motion
handler calls gtk_drag_get_data() to inspect the dragged data.
There’s no way to set a default action here, you can use the #GtkWidget::drag-motion callback for that. Here’s an example which selects the action to use depending on whether the control key is pressed or not:
static void
drag_motion (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
guint time)
{
GdkModifierType mask;
gdk_window_get_pointer (gtk_widget_get_window (widget),
NULL, NULL, &mask);
if (mask & GDK_CONTROL_MASK)
gdk_drag_status (context, GDK_ACTION_COPY, time);
else
gdk_drag_status (context, GDK_ACTION_MOVE, time);
}
which types of default drag behavior to use
a pointer to an array of #GtkTargetEntrys indicating the drop types that this widget
will accept, or %NULL. Later you can access the list with gtk_drag_dest_get_target_list() and gtk_drag_dest_find_target().
a bitmask of possible actions for a drop onto this widget
.
Sets this widget as a proxy for drops to another window.
the window to which to forward drag events
the drag protocol which the proxy_window
accepts (You can use gdk_drag_get_protocol() to determine this)
If %TRUE, send the same coordinates to the destination, because it is an embedded subwindow.
Sets the target types that this widget can accept from drag-and-drop. The widget must first be made into a drag destination with gtk_drag_dest_set().
list of droppable targets, or %NULL for none
Tells the widget to emit #GtkWidget::drag-motion and #GtkWidget::drag-leave events regardless of the targets and the %GTK_DEST_DEFAULT_MOTION flag.
This may be used when a widget wants to do generic actions regardless of the targets that the source offers.
whether to accept all targets
Clears information about a drop destination set with gtk_drag_dest_set(). The widget will no longer receive notification of drags.
Gets the data associated with a drag. When the data
is received or the retrieval fails, GTK+ will emit a
#GtkWidget::drag-data-received signal. Failure of the retrieval
is indicated by the length field of the selection_data
signal parameter being negative. However, when gtk_drag_get_data()
is called implicitely because the %GTK_DEST_DEFAULT_DROP was set,
then the widget will not receive notification of failed
drops.
the drag context
the target (form of the data) to retrieve
a timestamp for retrieving the data. This will generally be the time received in a #GtkWidget::drag-motion or #GtkWidget::drag-drop signal
Highlights a widget as a currently hovered drop target. To end the highlight, call gtk_drag_unhighlight(). GTK+ calls this automatically if %GTK_DEST_DEFAULT_HIGHLIGHT is set.
Add the writable image targets supported by #GtkSelectionData to
the target list of the drag source. The targets
are added with info
= 0. If you need another value,
use gtk_target_list_add_image_targets() and
gtk_drag_source_set_target_list().
Add the text targets supported by #GtkSelectionData to
the target list of the drag source. The targets
are added with info
= 0. If you need another value,
use gtk_target_list_add_text_targets() and
gtk_drag_source_set_target_list().
Add the URI targets supported by #GtkSelectionData to
the target list of the drag source. The targets
are added with info
= 0. If you need another value,
use gtk_target_list_add_uri_targets() and
gtk_drag_source_set_target_list().
Gets the list of targets this widget can provide for drag-and-drop.
Sets up a widget so that GTK+ will start a drag operation when the user clicks and drags on the widget. The widget must have a window.
the bitmask of buttons that can start the drag
the table of targets that the drag will support, may be %NULL
the bitmask of possible actions for a drag from this widget
Sets the icon that will be used for drags from a particular source to a themed icon. See the docs for #GtkIconTheme for more details.
name of icon to use
Sets the icon that will be used for drags from a particular widget
from a #GdkPixbuf. GTK+ retains a reference for pixbuf
and will
release it when it is no longer needed.
the #GdkPixbuf for the drag icon
Sets the icon that will be used for drags from a particular source to a stock icon.
the ID of the stock icon to use
Changes the target types that this widget offers for drag-and-drop. The widget must first be made into a drag source with gtk_drag_source_set().
list of draggable targets, or %NULL for none
Undoes the effects of gtk_drag_source_set().
Removes a highlight set by gtk_drag_highlight() from a widget.
Draws widget
to cr
. The top left corner of the widget will be
drawn to the currently set origin point of cr
.
You should pass a cairo context as cr
argument that is in an
original state. Otherwise the resulting drawing is undefined. For
example changing the operator using cairo_set_operator() or the
line width using cairo_set_line_width() might have unwanted side
effects.
You may however change the context’s transform matrix - like with
cairo_scale(), cairo_translate() or cairo_set_matrix() and clip
region with cairo_clip() prior to calling this function. Also, it
is fine to modify the context with cairo_save() and
cairo_push_group() prior to calling this function.
Note that special-purpose widgets may contain special code for rendering to the screen and might appear differently on screen and when rendered using gtk_widget_draw().
GtkWidget is the base class all widgets in GTK+ derive from. It manages the widget lifecycle, states and style.
Height-for-width Geometry Management # {#geometry-management}
GTK+ uses a height-for-width (and width-for-height) geometry management system. Height-for-width means that a widget can change how much vertical space it needs, depending on the amount of horizontal space that it is given (and similar for width-for-height). The most common example is a label that reflows to fill up the available width, wraps to fewer lines, and therefore needs less height.
Height-for-width geometry management is implemented in GTK+ by way of five virtual methods:
There are some important things to keep in mind when implementing height-for-width and when using it in container implementations.
The geometry management system will query a widget hierarchy in only one orientation at a time. When widgets are initially queried for their minimum sizes it is generally done in two initial passes in the #GtkSizeRequestMode chosen by the toplevel.
For example, when queried in the normal %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH mode: First, the default minimum and natural width for each widget in the interface will be computed using gtk_widget_get_preferred_width(). Because the preferred widths for each container depend on the preferred widths of their children, this information propagates up the hierarchy, and finally a minimum and natural width is determined for the entire toplevel. Next, the toplevel will use the minimum width to query for the minimum height contextual to that width using gtk_widget_get_preferred_height_for_width(), which will also be a highly recursive operation. The minimum height for the minimum width is normally used to set the minimum size constraint on the toplevel (unless gtk_window_set_geometry_hints() is explicitly used instead).
After the toplevel window has initially requested its size in both dimensions it can go on to allocate itself a reasonable size (or a size previously specified with gtk_window_set_default_size()). During the recursive allocation process it’s important to note that request cycles will be recursively executed while container widgets allocate their children. Each container widget, once allocated a size, will go on to first share the space in one orientation among its children and then request each child's height for its target allocated width or its width for allocated height, depending. In this way a #GtkWidget will typically be requested its size a number of times before actually being allocated a size. The size a widget is finally allocated can of course differ from the size it has requested. For this reason, #GtkWidget caches a small number of results to avoid re-querying for the same sizes in one allocation cycle.
See [GtkContainer’s geometry management section][container-geometry-management] to learn more about how height-for-width allocations are performed by container widgets.
If a widget does move content around to intelligently use up the allocated size then it must support the request in both #GtkSizeRequestModes even if the widget in question only trades sizes in a single orientation.
For instance, a #GtkLabel that does height-for-width word wrapping will not expect to have #GtkWidgetClass.get_preferred_height() called because that call is specific to a width-for-height request. In this case the label must return the height required for its own minimum possible width. By following this rule any widget that handles height-for-width or width-for-height requests will always be allocated at least enough space to fit its own content.
Here are some examples of how a %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH widget generally deals with width-for-height requests, for #GtkWidgetClass.get_preferred_height() it will do:
And in #GtkWidgetClass.get_preferred_width_for_height() it will simply return the minimum and natural width:
Often a widget needs to get its own request during size request or allocation. For example, when computing height it may need to also compute width. Or when deciding how to use an allocation, the widget may need to know its natural size. In these cases, the widget should be careful to call its virtual methods directly, like this:
It will not work to use the wrapper functions, such as gtk_widget_get_preferred_width() inside your own size request implementation. These return a request adjusted by #GtkSizeGroup and by the #GtkWidgetClass.adjust_size_request() virtual method. If a widget used the wrappers inside its virtual method implementations, then the adjustments (such as widget margins) would be applied twice. GTK+ therefore does not allow this and will warn if you try to do it.
Of course if you are getting the size request for another widget, such as a child of a container, you must use the wrapper APIs. Otherwise, you would not properly consider widget margins, #GtkSizeGroup, and so forth.
Since 3.10 GTK+ also supports baseline vertical alignment of widgets. This means that widgets are positioned such that the typographical baseline of widgets in the same row are aligned. This happens if a widget supports baselines, has a vertical alignment of %GTK_ALIGN_BASELINE, and is inside a container that supports baselines and has a natural “row” that it aligns to the baseline, or a baseline assigned to it by the grandparent.
Baseline alignment support for a widget is done by the #GtkWidgetClass.get_preferred_height_and_baseline_for_width() virtual function. It allows you to report a baseline in combination with the minimum and natural height. If there is no baseline you can return -1 to indicate this. The default implementation of this virtual function calls into the #GtkWidgetClass.get_preferred_height() and #GtkWidgetClass.get_preferred_height_for_width(), so if baselines are not supported it doesn’t need to be implemented.
If a widget ends up baseline aligned it will be allocated all the space in the parent as if it was %GTK_ALIGN_FILL, but the selected baseline can be found via gtk_widget_get_allocated_baseline(). If this has a value other than -1 you need to align the widget such that the baseline appears at the position.
Style Properties
#GtkWidget introduces “style properties” - these are basically object properties that are stored not on the object, but in the style object associated to the widget. Style properties are set in [resource files][gtk3-Resource-Files]. This mechanism is used for configuring such things as the location of the scrollbar arrows through the theme, giving theme authors more control over the look of applications without the need to write a theme engine in C.
Use gtk_widget_class_install_style_property() to install style properties for a widget class, gtk_widget_class_find_style_property() or gtk_widget_class_list_style_properties() to get information about existing style properties and gtk_widget_style_get_property(), gtk_widget_style_get() or gtk_widget_style_get_valist() to obtain the value of a style property.
GtkWidget as GtkBuildable
The GtkWidget implementation of the GtkBuildable interface supports a custom
<accelerator>
element, which has attributes named ”key”, ”modifiers” and ”signal” and allows to specify accelerators.An example of a UI definition fragment specifying an accelerator:
|[
Finally, GtkWidget allows style information such as style classes to be associated with widgets, using the custom
<style>
element:|[
Typically, you'll place the template fragment into a file that is bundled with your project, using #GResource. In order to load the template, you need to call gtk_widget_class_set_template_from_resource() from the class initialization of your #GtkWidget type:
You will also need to call gtk_widget_init_template() from the instance initialization function:
You can access widgets defined in the template using the gtk_widget_get_template_child() function, but you will typically declare a pointer in the instance private data structure of your type using the same name as the widget in the template definition, and call gtk_widget_class_bind_template_child_private() with that name, e.g.
You can also use gtk_widget_class_bind_template_callback() to connect a signal callback defined in the template with a function visible in the scope of the class, e.g.