Package: gtk
Class gtk:widget
Superclassesgtk:buildable, gobject:object, common-lisp:standard-object, common-lisp:t Documented Subclassesgtk:calendar, gtk:cell-view, gtk:container, gtk:drawing-area, gtk:entry, gtk:hsv, gtk:invisible, gtk:level-bar, gtk:misc, gtk:progress-bar, gtk:range, gtk:separator, gtk:spinner, gtk:switch Direct SlotsDetails The gtk:widget class is the base class all widgets in GTK derive
from. It manages the widget life cycle, states and style. Height-for-width Geometry ManagementGTK 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.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 :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. If a widget ends up baseline aligned it will be allocated all the space in the parent as if it was :fill, but the selected baseline can be found via the gtk:widget-allocated-baseline function. If this has a value other than -1 you need to align the widget such that the baseline appears at the position. Style PropertiesThe gtk:widget class 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. 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.Use the gtk:widget-class-find-style-property or gtk:widget-class-list-style-properties functions to get information about existing style properties and the gtk:widget-style-property function to obtain the value of a style property. GtkWidget as GtkBuildableThe gtk:widget implementation of the gtk:buildable interface supports a custom <accelerator> element, which has attributes named key, modifiers and signal and allows to specify accelerators.Example: A UI definition fragment specifying an accelerator <object class="GtkButton"> <accelerator key="q" modifiers="GDK_CONTROL_MASK" signal="clicked"/> </object>In addition to accelerators, the gtk:widget implementation also support a custom <accessible> element, which supports actions and relations. Properties on the accessible implementation of an object can be set by accessing the internal child "accessible" of a gtk:widget object. Example: A UI definition fragment specifying an accessible <object class="GtkButton" id="label1"/> <property name="label">I am a Label for a Button</property> </object> <object class="GtkButton" id="button1"> <accessibility> <action action_name="click" translatable="yes">Click the button.</action> <relation target="label1" type="labelled-by"/> </accessibility> <child internal-child="accessible"> <object class="AtkObject" id="a11y-button1"> <property name="AtkObject::name">Clickable Button</property> </object> </child> </object>Finally, the gtk:widget implementation allows style information such as style classes to be associated with widgets, using the custom <style> element: Example: A UI definition fragment specifying an style class <object class="GtkButton" id="button1"> <style> <class name="my-special-button-class"/> <class name="dark-button"/> </style> </object> Building composite widgets from template XMLThe gtk:widget implementation exposes some facilities to automate the proceedure of creating composite widgets using the gtk:builder interface description language.To create composite widgets with gtk:builder XML, one must associate the interface description with the widget class at class initialization time using the gtk:widget-class-set-template function. The interface description semantics expected in composite template descriptions is slightly different from regulare gtk:builder XML. Unlike regular interface descriptions, the gtk:widget-class-set-template function will expect a <template> tag as a direct child of the toplevel <interface> tag. The <template> tag must specify the "class" attribute which must be the type name of the widget. Optionally, the "parent" attribute may be specified to specify the direct parent type of the widget type, this is ignored by the gtk:builder object but required for Glade to introspect what kind of properties and internal children exist for a given type when the actual type does not exist. The XML which is contained inside the <template> tag behaves as if it were added to the <object> tag defining the widget itself. You may set properties on the widget by inserting <property> tags into the <template> tag, and also add <child> tags to add children and extend the widget in the normal way you would with <object> tags. Additionally, <object> tags can also be added before and after the initial <template> tag in the normal way, allowing one to define auxilary objects which might be referenced by other widgets declared as children of the <template> tag. Example: A gtk:builder template definition <interface> <template class="FooWidget" parent="GtkBox"> <property name="orientation">GTK_ORIENTATION_HORIZONTAL</property> <property name="spacing">4</property> <child> <object class="GtkButton" id="hello_button"> <property name="label">Hello World</property> </object> </child> <child> <object class="GtkButton" id="goodbye_button"> <property name="label">Goodbye World</property> </object> </child> </template> </interface> Style Property Detailscursor-aspect-ratio The cursor-aspect-ratio style property of type :float (Read) Aspect ratio with which to draw insertion cursor. Allowed values: [0.0,1.0] Default value: 0.04 cursor-color The cursor-color style property of type gdk:color (Read ) Color with which to draw insertion cursor. focus-line-pattern The focus-line-pattern style property of type :string (Read) Dash pattern used to draw the focus indicator. Warning: The focus-line-pattern style property has been deprecated since version 3.14 and should not be used in newly written code. Use the outline-style CSS property instead. Default value: "001001" focus-line-width The focus-line-width style property of type :int (Read) Width, in pixels, of the focus indicator line. Warning: The focus-line-width style property has been deprecated since version 3.14 and should not be used in newly written code. Use the outline-width CSS property instead. Allowed values: >= 0 Default value: 1 focus-padding The focus-padding style property of type :int (Read) Width, in pixels, between focus indicator and the widget 'box'. Warning: The focus-padding style property has been deprecated since version 3.14 and should not be used in newly written code. Use the padding CSS property instead. Allowed values: >= 0 Default value: 1 interior-focus The interior-focus style property of type :boolean (Read) Whether to draw the focus indicator inside widgets. Warning: The interior-focus style property has been deprecated since version 3.14 and should not be used in newly written code. Use the outline CSS property instead. Default value: true link-color The link-color style property of type gdk:color (Read) Defines the color of unvisited links. Warning: The link-color style property has been deprecated since version 3.12 and should not be used in newly written code. Links now use a separate state flags for selecting different theming. This style property is ignored. scroll-arrow-hlength The scroll-arrow-hlength style property of type :int (Read) Defines the length of horizontal scroll arrows. Allowed values: >= 1 Default value: 16 scroll-arrow-vlength The scroll-arrow-vlength style property of type :int (Read) Defines the length of vertical scroll arrows. Allowed values: >= 1 Default value: 16 secondary-cursor-color The secondary-cursor-color style property of type gdk:color (Read) Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text. separator-height The separator-height style property of type :int (Read) Defines the height of separators. This property only takes effect if the wide-separators style property is true. Warning: The separator-height style property has been deprecated since version 3.20 and should not be used in newly written code. Use the standard min-height CSS property on the separator elements to size separators. The value of this style property is ignored. Allowed values: >= 0 Default value: 0 separator-width The separator-width style property of type :int (Read) Defines the width of separators. This property only takes effect if the wide-separators style property is true. Warning: The separator-width style property has been deprecated since version 3.20 and should not be used in newly written code. Use the standard min-height CSS property on the separator elements to size separators. The value of this style property is ignored. Allowed values: >= 0 Default value: 0 text-handle-height The text-handle-height style property of type :int (Read) Height of text selection handles. Allowed values: >= 1 Default value: 24 text-handle-width The text-handle-width style property of type :int (Read) Width of text selection handles. Allowed values: >= 1 Default value: 20 visited-link-color The visited-link-color style property of type gdk:color (Read) Defines the color of visited links. Warning: The visited-link-color style property has been deprecated since version 3.12 and should not be used in newly written code. Links now use a separate state flags for selecting different theming. This style property is ignored. wide-separators The wide-separators style property of type :boolean (Read) Defines whether separators have configurable width and should be drawn using a box instead of a line. Default value: false window-dragging The window-dragging style property of type :boolean (Read) Whether windows can be dragged by clicking on empty areas. Default value: false Signal DetailsThe "accel-closures-changed" signallambda (widget)
The "can-activate-accel" signallambda (widget signal) :run-last
The "child-notify" signallambda (widget pspec) :no-hooks
The "composited-changed" signallambda (widget) :action
Warning: The "composited-changed" signal has been deprecated since version 3.22 and should not be used in newly written code. Use the "composited-changed" signal of the gdk:screen class instead. The "configure-event" signallambda (widget event) :run-last
The "damage-event" signallambda (widget event) :run-last
The "delete-event" signallambda (widget event) :run-last
The "destroy" signallambda (widget) :no-hooks
The "destroy-event" signallambda (widget event) :run-last
The "direction-changed" signallambda (widget direction) :run-first
The "drag-begin" signallambda (widget context) :run-last
The "drag-data-delete" signallambda (widget context) :run-last
The "drag-data-get" signallambda (widget context selection info time) :run-last
The "drag-data-received" signallambda (widget context x y selection info time) :run-last
void drag_data_received (GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *data, guint info, guint time) { if ((data->length >= 0) && (data->format == 8)) { GdkDragAction action; The "drag-drop" signallambda (widget context x y time) :run-last
The "drag-end" signallambda (widget context) :run-last
The "drag-failed" signallambda (widget context result) :run-last
The "drag-leave" signallambda (widget context time) :run-last
The "drag-motion" signallambda (widget context x y time) :run-last
If the decision whether the drop will be accepted or rejected cannot be made based solely on the cursor position and the type of the data, the handler may inspect the dragged data by calling the gtk:drag-data function and defer the gdk:drag-status function call to the "drag-data-received" signal handler. Note that you cannot pass the :drop, :motion or :all values of the gtk:dest-defaults flags to the gtk:drag-dest-set function when using the "drag-motion" signal that way. Also note that there is no "drag-enter" signal. The drag receiver has to keep track of whether he has received any "drag-motion" signals since the last "drag-leave" signal and if not, treat the "drag-motion" signal as an "enter" signal. Upon an "enter", the handler will typically highlight the drop site with the gtk:drag-highlight function. static void drag_motion (GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint time) { GdkAtom target; The "draw" signallambda (widget cr) :run-last
The "enter-notify-event" signallambda (widget event) :run-last
The "event" signallambda (widget event) :run-last
The "event-after" signallambda (widget event)
The "focus" signallambda (widget direction) :run-last
The "focus-in-event" signallambda (widget event) :run-last
The "focus-out-event" signallambda (widget event) :run-last
The "grab-broken-event" signallambda (widget event) : run-last
The "grab-focus" signallambda (widget) :action
The "grab-notify" signallambda (widget grabbed) :run-first
The "hide" signallambda (widget) :run-first
The "hierachy-changed" signallambda (widget toplevel) :run-last
The "key-press-event" signallambda (widget event) :run-last
The "key-release-event" signallambda (widget event) :run-last
The "leave-notify-event" signallambda (widget event) :run-last
The "map" signallambda (widget) :run-first
The "map-event" signallambda (widget event) :run-last
The "mnemonic-activate" signallambda (widget cycling) :run-last
The "motion-notify-event" signallambda (widget event) :run-last
The "move-focus" signallambda (widget direction) :action
The "parent-set" signallambda (widget parent) :run-first
The "property-notify-event" signallambda (widget event) :run-last
The "proximity-in-event" signallambda (widget event) :run-last
The "proximity-out-event" signallambda (widget event) :run-last
The "query-tooltip" signallambda (widget x y mode tooltip) :run-last
The "realize" signallambda (widget) :run-first
The "screen-changed" signallambda (widget screen) :run-last
The "scroll-event" signallambda (widget event) :run-last
The "selection-clear-event" signallambda (widget event) :run-last
The "selection-get" signallambda (widget data info time) :run-last
The "selection-notify-event" signallambda (widget event) :run-last
The "selection-received" signallambda (widget data time) :run-last
The "selection-request-event" signallambda (widget event) :run-last
The "show" signallambda (widget)
The "show-help" signallambda (widget help) :action
The "size-allocate" signallambda (widget allocation) :run-first
The "state-changed" signallambda (widget state) :run-first
Warning: The "state-changed" signal is deprecated since version 3.0 and should not be used in newly written code. Use the "state-flags-changed" signal instead. The "state-flags-changed" signallambda (widget flags) :run-first
The "style-set" signallambda (widget style) :run-first
Warning: The "style-set" signal has been deprecated since version 3.0 and should not be used in newly written code. Use the "style-updated" signal. The "style-updated" signallambda (widget) :run-first
The "touch-event" signallambda (widget event) :run-last
The "unmap" signallambda (widget) :run-first
The "unmap-event" signallambda (widget event) :run-last
The "unrealize" signallambda (widget) :run-last
The "visibility-notify-event" signallambda (widget event) :run-last
Warning: The "visibility-notify-event" signal has been deprecated since version 3.12 and should not be used in newly written code. Modern composited windowing systems with pervasive transparency make it impossible to track the visibility of a window reliably, so this signal can not be guaranteed to provide useful information. The "window-state-event" signallambda (widget event) :run-last
| Slot Access FunctionsInherited Slot Access FunctionsSee also |
2025-07-17