GtkWidget is the abstract base class for all UI components in React GTK. While you typically don’t use GtkWidget directly, all other components inherit its props and behaviors.
Common Props
These props are available on all widgets:Layout
Override for width request of the widget in pixels.
Override for height request of the widget in pixels.
How to distribute horizontal space if widget gets extra space.Options:
GtkAlign.FILL, GtkAlign.START, GtkAlign.END, GtkAlign.CENTERHow to distribute vertical space if widget gets extra space.Options:
GtkAlign.FILL, GtkAlign.START, GtkAlign.END, GtkAlign.CENTERWhether to expand horizontally to fill available space.Default:
falseWhether to expand vertically to fill available space.Default:
falseWhether to use the
hexpand property.Default: falseWhether to use the
vexpand property.Default: falseMargins
Margin on the start edge (left in LTR, right in RTL) in pixels.
Margin on the end edge (right in LTR, left in RTL) in pixels.
Margin on the top edge in pixels.
Margin on the bottom edge in pixels.
Visibility & Interaction
Whether the widget is visible.Default:
trueWhether the widget responds to input.Default:
trueWhether the widget or any of its descendants can accept input focus.Default: Varies by widget type
Whether the widget can receive pointer events.Default:
trueWhether this widget itself will accept input focus.Default: Varies by widget type
Whether the widget should grab focus when clicked with the mouse.Default: Varies by widget type
Whether the widget has input focus.
Whether the widget is the default widget.
Whether the widget will receive the default action when focused.Default:
falseStyling
A list of CSS classes applied to this widget.
The requested opacity of the widget (0.0 to 1.0).Default:
1.0The cursor to display when hovering over the widget.Options:
'none', 'default', 'pointer', 'text', 'wait', 'crosshair', 'help', 'move', 'not-allowed', and many more.How content outside the widget’s content area is treated.Options:
GtkOverflow.VISIBLE, GtkOverflow.HIDDENTooltips
Enables or disables the tooltip for this widget.Default:
falseSets the text of the tooltip as plain text.
Sets the text of the tooltip with Pango markup.
Other
The name of the widget. Used for identification and CSS styling.
The accessible role of the widget. Cannot be changed once set.
The layout manager to compute preferred size and allocate children.
Events
Lifecycle Events
Emitted when the widget is associated with a GdkSurface (about to be drawn).
Emitted when the GdkSurface associated with the widget is destroyed.
Emitted when the widget is going to be mapped (visible with visible parents).
Emitted when the widget is going to be unmapped (hidden).
Emitted when the widget is shown.
Emitted when the widget is hidden.
Emitted when all holders should release their references to the widget.
Focus & Navigation
Emitted when focus is moved.
Emitted if keyboard navigation fails. Return
true to stop navigation, false to propagate.Emitted when a widget is activated via a mnemonic. Return
true to stop propagation.State Changes
Emitted when a property value changes.
Emitted when the widget state changes.
Emitted when the text direction changes.
Tooltips
onQueryTooltip
(self: GtkWidgetImpl, x: number, y: number, isKeyboardMode: boolean, tooltip: GtkTooltip) => boolean
Emitted when the widget’s tooltip is about to be shown. Return
true to show tooltip, false otherwise.Instance Properties
When using a ref on any widget, you can access these properties:visible
Get or set widget visibility:name
Get or set widget name:parent
Get the widget’s parent:root
Get the root widget of the widget tree:scaleFactor
Get the scale factor of the widget (for HiDPI displays):Instance Methods
realize()
Creates the GDK resources associated with the widget:unrealize()
Frees all GDK resources associated with the widget:unparent()
Dissociates the widget from its parent:detach()
Destroys the widget instance by unparenting and unrealizing:Usage Examples
Centered Widget
Widget with Margins
Widget with Tooltip
Custom Cursor
Fixed Size Widget
Widget with CSS Classes
Conditional Visibility
Notes
All other components in React GTK inherit these props. You can use any
GtkWidget prop on components like GtkButton, GtkLabel, GtkBox, etc.The
visible prop controls visibility, but hidden widgets still take up layout space unless completely removed from the tree.