Gtk.Widget¶
- Subclasses:
Gtk.ActionBar
,Gtk.AppChooserButton
,Gtk.AppChooserWidget
,Gtk.AspectFrame
,Gtk.Box
,Gtk.Button
,Gtk.Calendar
,Gtk.CellView
,Gtk.CenterBox
,Gtk.CheckButton
,Gtk.ColorButton
,Gtk.ColorChooserWidget
,Gtk.ColorDialogButton
,Gtk.ColumnView
,Gtk.ComboBox
,Gtk.DragIcon
,Gtk.DrawingArea
,Gtk.DropDown
,Gtk.EditableLabel
,Gtk.Entry
,Gtk.Expander
,Gtk.FileChooserWidget
,Gtk.Fixed
,Gtk.FlowBox
,Gtk.FlowBoxChild
,Gtk.FontButton
,Gtk.FontChooserWidget
,Gtk.FontDialogButton
,Gtk.Frame
,Gtk.GLArea
,Gtk.Grid
,Gtk.HeaderBar
,Gtk.IconView
,Gtk.Image
,Gtk.InfoBar
,Gtk.Inscription
,Gtk.Label
,Gtk.LevelBar
,Gtk.ListBase
,Gtk.ListBox
,Gtk.ListBoxRow
,Gtk.MediaControls
,Gtk.MenuButton
,Gtk.Notebook
,Gtk.Overlay
,Gtk.Paned
,Gtk.PasswordEntry
,Gtk.Picture
,Gtk.Popover
,Gtk.PopoverMenuBar
,Gtk.ProgressBar
,Gtk.Range
,Gtk.Revealer
,Gtk.ScaleButton
,Gtk.Scrollbar
,Gtk.ScrolledWindow
,Gtk.SearchBar
,Gtk.SearchEntry
,Gtk.Separator
,Gtk.ShortcutLabel
,Gtk.ShortcutsShortcut
,Gtk.SpinButton
,Gtk.Spinner
,Gtk.Stack
,Gtk.StackSidebar
,Gtk.StackSwitcher
,Gtk.Statusbar
,Gtk.Switch
,Gtk.Text
,Gtk.TextView
,Gtk.TreeExpander
,Gtk.TreeView
,Gtk.Video
,Gtk.Viewport
,Gtk.Window
,Gtk.WindowControls
,Gtk.WindowHandle
Methods¶
- Inherited:
- Structs:
Virtual Methods¶
- Inherited:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Properties¶
- Inherited:
Name |
Type |
Flags |
Short Description |
---|---|---|---|
r/w/en |
|||
r/w/en |
|||
[ |
r/w |
||
r/w/co |
|||
r/w/en |
|||
r/w/en |
|||
r/w/en |
|||
r/w/en |
|||
r/en |
|||
r/en |
|||
r/w/en |
|||
r/w/en |
|||
r/w/en |
|||
r/w/en |
|||
r/w/en |
|||
r/w/en |
|||
r/w/en |
|||
r/w/en |
|||
r/w/en |
|||
r/w |
|||
r/w/en |
|||
r/w/en |
|||
r/en |
|||
r/w/en |
|||
r/en |
|||
r |
|||
r/w/en |
|||
r/w/en |
|||
r/w/en |
|||
r/w/en |
|||
r/w/en |
|||
r/w/en |
|||
r/w/en |
|||
r/w/en |
Signals¶
- Inherited:
Name |
Short Description |
---|---|
Signals that all holders of a reference to the widget should release the reference that they hold. |
|
Emitted when the text direction of a widget changes. |
|
Emitted when widget is hidden. |
|
Emitted if keyboard navigation fails. |
|
Emitted when widget is going to be mapped. |
|
Emitted when a widget is activated via a mnemonic. |
|
Emitted when the focus is moved. |
|
Emitted when the widget’s tooltip is about to be shown. |
|
Emitted when widget is associated with a |
|
Emitted when widget is shown. |
|
Emitted when the widget state changes. |
|
Emitted when widget is going to be unmapped. |
|
Emitted when the |
Fields¶
- Inherited:
Name |
Type |
Access |
Description |
---|---|---|---|
parent_instance |
r |
Class Details¶
- class Gtk.Widget(**kwargs)¶
- Bases:
GObject.InitiallyUnowned
,Gtk.Accessible
,Gtk.Buildable
,Gtk.ConstraintTarget
- Abstract:
Yes
- Structure:
The base class for all widgets.
GtkWidget
is the base class all widgets in GTK derive from. It manages the widget lifecycle, layout, states and style.### Height-for-width 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 two virtual methods:
[vfunc`Gtk`.Widget.get_request_mode]
[vfunc`Gtk`.Widget.measure]
There are some important things to keep in mind when implementing height-for-width and when using it in widget implementations.
If you implement a direct
GtkWidget
subclass that supports height-for-width or width-for-height geometry management for itself or its child widgets, the [vfunc`Gtk`.Widget.get_request_mode] virtual function must be implemented as well and return the widget’s preferred request mode. The default implementation of this virtual function returnsGtk.SizeRequestMode.CONSTANT_SIZE
, which means that the widget will only ever get -1 passed as the for_size value to its [vfunc`Gtk`.Widget.measure] implementation.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 [enum`Gtk`.SizeRequestMode] chosen by the toplevel.
For example, when queried in the normal
Gtk.SizeRequestMode.HEIGHT_FOR_WIDTH
mode:First, the default minimum and natural width for each widget in the interface will be computed using [id`gtk_widget_measure`] with an orientation of
Gtk.Orientation.HORIZONTAL
and a for_size of -1. Because the preferred widths for each widget 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 [id`gtk_widget_measure`] with an orientation ofGtk.Orientation.VERTICAL
and a for_size of the just computed width. This 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.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 [method`Gtk`.Window.set_default_size]). During the recursive allocation process it’s important to note that request cycles will be recursively executed while widgets allocate their children. Each 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.If a widget does move content around to intelligently use up the allocated size then it must support the request in both ``GtkSizeRequestMode``s even if the widget in question only trades sizes in a single orientation.
For instance, a [class`Gtk`.Label] that does height-for-width word wrapping will not expect to have [vfunc`Gtk`.Widget.measure] with an orientation of
Gtk.Orientation.VERTICAL
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.SizeRequestMode.HEIGHT_FOR_WIDTH
widget generally deals with width-for-height requests:```c static void foo_widget_measure (
Gtk.Widget
*widget,Gtk.Orientation
orientation, int for_size, int *minimum_size, int *natural_size, int *minimum_baseline, int *natural_baseline) { if (orientation ==Gtk.Orientation.HORIZONTAL
) { // Calculate minimum and natural width } else // VERTICAL { if (i_am_in_height_for_width_mode) { int min_width, dummy;// First, get the minimum width of our widget GTK_WIDGET_GET_CLASS (widget)->measure (widget,
Gtk.Orientation.HORIZONTAL
, -1, &min_width, &dummy, &dummy, &dummy);// Now use the minimum width to retrieve the minimum and natural height to display // that width. GTK_WIDGET_GET_CLASS (widget)->measure (widget,
Gtk.Orientation.VERTICAL
, min_width, minimum_size, natural_size, &dummy, &dummy); } else { // … some widgets do both. } } } ```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 in the code example above.
It will not work to use the wrapper function [method`Gtk`.Widget.measure] inside your own [vfunc`Gtk`.Widget.size_allocate] implementation. These return a request adjusted by [class`Gtk`.SizeGroup], the widget’s align and expand flags, as well as its CSS style.
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 widget, you must use [id`gtk_widget_measure`]; otherwise, you would not properly consider widget margins, [class`Gtk`.SizeGroup], and so forth.
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 using baselines, and is inside a widget 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 also done by the [vfunc`Gtk`.Widget.measure] virtual function. It allows you to report both a minimum and natural size.
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 [id`gtk_widget_get_baseline`]. If the baseline has a value other than -1 you need to align the widget such that the baseline appears at the position.###
Gtk.Widget
asGtk.Buildable
The
GtkWidget
implementation of theGtkBuildable
interface supports various custom elements to specify additional aspects of widgets that are not directly expressed as properties.If the widget uses a [class`Gtk`.LayoutManager],
GtkWidget
supports a custom<layout>
element, used to define layout properties:``xml <object class=”GtkGrid” id=”my_grid”>
- <child>
- <object class=”GtkLabel” id=”label1”>
<property name=”label”>Description</property> <layout>
<property name=”column”>0</property> <property name=”row”>0</property> <property name=”row-span”>1</property> <property name=”column-span”>1</property>
</layout>
</object>
</child> <child>
- <object class=”GtkEntry” id=”description_entry”>
- <layout>
<property name=”column”>1</property> <property name=”row”>0</property> <property name=”row-span”>1</property> <property name=”column-span”>1</property>
</layout>
</object>
</child>
</object> ``
GtkWidget
allows style information such as style classes to be associated with widgets, using the custom<style>
element:``xml <object class=”GtkButton” id=”button1”>
- <style>
<class name=”my-special-button-class”/> <class name=”dark-button”/>
</style>
</object> ``
GtkWidget
allows defining accessibility information, such as properties, relations, and states, using the custom<accessibility>
element:``xml <object class=”GtkButton” id=”button1”>
- <accessibility>
<property name=”label”>Download</property> <relation name=”labelled-by”>label1</relation>
</accessibility>
</object> ``
### Building composite widgets from template XML
``GtkWidget ``exposes some facilities to automate the procedure of creating composite widgets using “templates”.
To create composite widgets with
GtkBuilder
XML, one must associate the interface description with the widget class at class initialization time using [method`Gtk`.WidgetClass.set_template].The interface description semantics expected in composite template descriptions is slightly different from regular [class`Gtk`.Builder] XML.
Unlike regular interface descriptions, [method`Gtk`.WidgetClass.set_template] 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 byGtkBuilder
but can be used by UI design tools 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 a widget by inserting<property>
tags into the<template>
tag, and also add<child>
tags to add children and extend a 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 auxiliary objects which might be referenced by other widgets declared as children of the<template>
tag.An example of a template definition:
``xml <interface>
- <template class=”FooWidget” parent=”GtkBox”>
<property name=”orientation”>horizontal</property> <property name=”spacing”>4</property> <child>
- <object class=”GtkButton” id=”hello_button”>
<property name=”label”>Hello World</property> <signal name=”clicked” handler=”hello_button_clicked” object=”FooWidget” swapped=”yes”/>
</object>
</child> <child>
- <object class=”GtkButton” id=”goodbye_button”>
<property name=”label”>Goodbye World</property>
</object>
</child>
</template>
</interface> ``
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 [method`Gtk`.WidgetClass.set_template_from_resource] from the class initialization of yourGtkWidget
type:```c static void foo_widget_class_init (FooWidgetClass *klass) { // …
Gtk.WidgetClass.set_template_from_resource
(GTK_WIDGET_CLASS (klass), “/com/example/ui/foowidget.ui”); } ```You will also need to call [method`Gtk`.Widget.init_template] from the instance initialization function:
```c static void foo_widget_init (FooWidget *self) {
Gtk.Widget.init_template
(GTK_WIDGET (self));// Initialize the rest of the widget… } ```
as well as calling [method`Gtk`.Widget.dispose_template] from the dispose function:
```c static void foo_widget_dispose (
GObject.Object
*gobject) { FooWidget *self = FOO_WIDGET (gobject);// Dispose objects for which you have a reference…
// Clear the template children for this widget type
Gtk.Widget.dispose_template
(GTK_WIDGET (self), FOO_TYPE_WIDGET);G_OBJECT_CLASS (foo_widget_parent_class)->dispose (gobject); } ```
You can access widgets defined in the template using the [id`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 [method`Gtk`.WidgetClass.bind_template_child_full] (or one of its wrapper macros [func`Gtk`.widget_class_bind_template_child] and [func`Gtk`.widget_class_bind_template_child_private]) with that name, e.g.
```c typedef struct {
Gtk.Widget
*hello_button;Gtk.Widget
*goodbye_button; } FooWidgetPrivate;G_DEFINE_TYPE_WITH_PRIVATE (FooWidget, foo_widget, GTK_TYPE_BOX)
static void foo_widget_dispose (
GObject.Object
*gobject) {Gtk.Widget.dispose_template
(GTK_WIDGET (gobject), FOO_TYPE_WIDGET);G_OBJECT_CLASS (foo_widget_parent_class)->dispose (gobject); }
static void foo_widget_class_init (FooWidgetClass *klass) { // … G_OBJECT_CLASS (klass)->dispose = foo_widget_dispose;
Gtk.WidgetClass.set_template_from_resource
(GTK_WIDGET_CLASS (klass), “/com/example/ui/foowidget.ui”); gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), FooWidget, hello_button); gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), FooWidget, goodbye_button); }static void foo_widget_init (FooWidget *widget) {
Gtk.Widget.init_template
(GTK_WIDGET (widget)); } ```You can also use [method`Gtk`.WidgetClass.bind_template_callback_full] (or is wrapper macro [func`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.
```c // the signal handler has the instance and user data swapped // because of the swapped=”yes” attribute in the template XML static void hello_button_clicked (FooWidget *self,
Gtk.Button
*button) { g_print (“Hello, world!\n”); }static void foo_widget_class_init (FooWidgetClass *klass) { // …
Gtk.WidgetClass.set_template_from_resource
(GTK_WIDGET_CLASS (klass), “/com/example/ui/foowidget.ui”); gtk_widget_class_bind_template_callback (GTK_WIDGET_CLASS (klass), hello_button_clicked); } ```- classmethod add_shortcut(shortcut)¶
- Parameters:
shortcut (
Gtk.Shortcut
) – theGtkShortcut
to add
Installs a shortcut in self.
Every instance created for self or its subclasses will inherit this shortcut and trigger it.
Shortcuts added this way will be triggered in the
Gtk.PropagationPhase.BUBBLE
phase, which means they may also trigger if child widgets have focus.This function must only be used in class initialization functions otherwise it is not guaranteed that the shortcut will be installed.
- classmethod bind_template_callback_full(callback_name, callback_symbol)¶
- Parameters:
callback_name (
str
) – The name of the callback as expected in the template XMLcallback_symbol (
GObject.Callback
) – The callback symbol
Declares a callback_symbol to handle callback_name from the template XML defined for widget_type.
This function is not supported after [method`Gtk`.WidgetClass.set_template_scope] has been used on self. See [method`Gtk`.BuilderCScope.add_callback_symbol].
Note that this must be called from a composite widget classes class initializer after calling [method`Gtk`.WidgetClass.set_template].
- classmethod bind_template_child_full(name, internal_child, struct_offset)¶
- Parameters:
name (
str
) – The “id” of the child defined in the template XMLinternal_child (
bool
) – Whether the child should be accessible as an “internal-child” when this class is used inGtk.Builder
XMLstruct_offset (
int
) – The structure offset into the composite widget’s instance public or private structure where the automated child pointer should be set, or 0 to not assign the pointer.
Automatically assign an object declared in the class template XML to be set to a location on a freshly built instance’s private data, or alternatively accessible via [method`Gtk`.Widget.get_template_child].
The struct can point either into the public instance, then you should use
G_STRUCT_OFFSET(WidgetType, member)
for struct_offset, or in the private struct, then you should useG_PRIVATE_OFFSET(WidgetType, member)
.An explicit strong reference will be held automatically for the duration of your instance’s life cycle, it will be released automatically when
GObjectClass.dispose()
runs on your instance and if a struct_offset that is!= 0
is specified, then the automatic location in your instance public or private data will be set toNone
. You can however access an automated child pointer the first time your classesGObjectClass.dispose()
runs, or alternatively in [signal`Gtk`.Widget::destroy].If internal_child is specified, [vfunc`Gtk`.Buildable.get_internal_child] will be automatically implemented by the
GtkWidget
class so there is no need to implement it manually.The wrapper macros [func`Gtk`.widget_class_bind_template_child], [func`Gtk`.widget_class_bind_template_child_internal], [func`Gtk`.widget_class_bind_template_child_private] and [func`Gtk`.widget_class_bind_template_child_internal_private] might be more convenient to use.
Note that this must be called from a composite widget classes class initializer after calling [method`Gtk`.WidgetClass.set_template].
- classmethod get_accessible_role()¶
- Returns:
the accessible role for the widget class
- Return type:
Retrieves the accessible role used by the given
GtkWidget
class.Different accessible roles have different states, and are rendered differently by assistive technologies.
See also: [method`Gtk`.Accessible.get_accessible_role].
- classmethod get_activate_signal()¶
- Returns:
a signal id, or 0 if the widget class does not specify an activation signal
- Return type:
Retrieves the signal id for the activation signal.
the activation signal is set using [method`Gtk`.WidgetClass.set_activate_signal].
- classmethod get_css_name()[source]¶
- Returns:
the CSS name of the given class
- Return type:
Gets the name used by this class for matching in CSS code.
See [method`Gtk`.WidgetClass.set_css_name] for details.
- classmethod get_default_direction()[source]¶
- Returns:
the current default direction.
- Return type:
Obtains the current default reading direction.
See [func`Gtk`.Widget.set_default_direction].
- classmethod get_layout_manager_type()¶
- Returns:
type of a
GtkLayoutManager
subclass, orGObject.TYPE_INVALID
- Return type:
Retrieves the type of the [class`Gtk`.LayoutManager] used by widgets of class self.
See also: [method`Gtk`.WidgetClass.set_layout_manager_type].
- classmethod install_action(action_name, parameter_type, activate)¶
- Parameters:
action_name (
str
) – a prefixed action name, such as “clipboard.paste”activate (
Gtk.WidgetActionActivateFunc
) – callback to use when the action is activated
This should be called at class initialization time to specify actions to be added for all instances of this class.
Actions installed by this function are stateless. The only state they have is whether they are enabled or not (which can be changed with [method`Gtk`.Widget.action_set_enabled]).
- classmethod install_property_action(action_name, property_name)¶
- Parameters:
Installs an action called action_name on self and binds its state to the value of the property_name property.
This function will perform a few sanity checks on the property selected via property_name. Namely, the property must exist, must be readable, writable and must not be construct-only. There are also restrictions on the type of the given property, it must be boolean, int, unsigned int, double or string. If any of these conditions are not met, a critical warning will be printed and no action will be added.
The state type of the action matches the property type.
If the property is boolean, the action will have no parameter and toggle the property value. Otherwise, the action will have a parameter of the same type as the property.
- classmethod query_action(index_)¶
- Parameters:
index (
int
) – position of the action to query- Returns:
True
if the action was found,False
if index_ is out of range- owner:
return location for the type where the action was defined
- action_name:
return location for the action name
- parameter_type:
return location for the parameter type
- property_name:
return location for the property name
- Return type:
(
bool
, owner:GObject.GType
, action_name:str
, parameter_type:GLib.VariantType
orNone
, property_name:str
orNone
)
Returns details about the index_-th action that has been installed for self during class initialization.
See [method`Gtk`.WidgetClass.install_action] for details on how to install actions.
Note that this function will also return actions defined by parent classes. You can identify those by looking at owner.
- classmethod set_accessible_role(accessible_role)¶
- Parameters:
accessible_role (
Gtk.AccessibleRole
) – theGtkAccessibleRole
used by the self
Sets the accessible role used by the given
GtkWidget
class.Different accessible roles have different states, and are rendered differently by assistive technologies.
- classmethod set_activate_signal(signal_id)¶
- Parameters:
signal_id (
int
) – the id for the activate signal
Sets the
GtkWidgetClass.activate_signal
field with the given signal_id.The signal will be emitted when calling [method`Gtk`.Widget.activate].
The signal_id must have been registered with
g_signal_new()
orGObject.signal_newv
() before calling this function.
- classmethod set_activate_signal_from_name(signal_name)¶
- Parameters:
signal_name (
str
) – the name of the activate signal of widget_type
Sets the
GtkWidgetClass.activate_signal
field with the signal id for the given signal_name.The signal will be emitted when calling [method`Gtk`.Widget.activate].
The signal_name of widget_type must have been registered with
GObject.signal_new
() orGObject.signal_newv
() before calling this function.
- classmethod set_css_name(name)¶
- Parameters:
name (
str
) – name to use
Sets the name to be used for CSS matching of widgets.
If this function is not called for a given class, the name set on the parent class is used. By default,
GtkWidget
uses the name “widget”.
- classmethod set_default_direction(dir)[source]¶
- Parameters:
dir (
Gtk.TextDirection
) – the new default direction. This cannot beGtk.TextDirection.NONE
.
Sets the default reading direction for widgets.
See [method`Gtk`.Widget.set_direction].
- classmethod set_layout_manager_type(type)¶
- Parameters:
type (
GObject.GType
) – The object type that implements theGtkLayoutManager
for self
Sets the type to be used for creating layout managers for widgets of self.
The given type must be a subtype of [class`Gtk`.LayoutManager].
This function should only be called from class init functions of widgets.
- classmethod set_template(template_bytes)¶
- Parameters:
template_bytes (
GLib.Bytes
) – AGBytes
holding theGtkBuilder
XML
This should be called at class initialization time to specify the
GtkBuilder
XML to be used to extend a widget.For convenience, [method`Gtk`.WidgetClass.set_template_from_resource] is also provided.
Note that any class that installs templates must call [method`Gtk`.Widget.init_template] in the widget’s instance initializer.
- classmethod set_template_from_resource(resource_name)¶
- Parameters:
resource_name (
str
) – The name of the resource to load the template from
A convenience function that calls [method`Gtk`.WidgetClass.set_template] with the contents of a
GResource
.Note that any class that installs templates must call [method`Gtk`.Widget.init_template] in the widget’s instance initializer.
- classmethod set_template_scope(scope)¶
- Parameters:
scope (
Gtk.BuilderScope
) – TheGtkBuilderScope
to use when loading the class template
For use in language bindings, this will override the default
GtkBuilderScope
to be used when parsingGtk.Builder
XML from this class’s template data.Note that this must be called from a composite widget classes class initializer after calling [method`Gtk`.WidgetClass.set_template].
- action_set_enabled(action_name, enabled)[source]¶
- Parameters:
Enable or disable an action installed with
Gtk.WidgetClass.install_action
().
- activate()[source]¶
-
For widgets that can be “activated” (buttons, menu items, etc.), this function activates them.
The activation will emit the signal set using [method`Gtk`.WidgetClass.set_activate_signal] during class initialization.
Activation is what happens when you press <kbd>Enter</kbd> on a widget during key navigation.
If you wish to handle the activation keybinding yourself, it is recommended to use [method`Gtk`.WidgetClass.add_shortcut] with an action created with [ctor`Gtk`.SignalAction.new].
If self isn’t activatable, the function returns
False
.
- activate_action(name, args)[source]¶
- Parameters:
name (
str
) – the name of the action to activateargs (
GLib.Variant
orNone
) – parameters to use
- Returns:
True
if the action was activated,False
if the action does not exist.- Return type:
Looks up the action in the action groups associated with self and its ancestors, and activates it.
If the action is in an action group added with [method`Gtk`.Widget.insert_action_group], the name is expected to be prefixed with the prefix that was used when the group was inserted.
The arguments must match the actions expected parameter type, as returned by
g_action_get_parameter_type()
.
- add_controller(controller)[source]¶
- Parameters:
controller (
Gtk.EventController
) – aGtkEventController
that hasn’t been added to a widget yet
Adds controller to self so that it will receive events.
You will usually want to call this function right after creating any kind of [class`Gtk`.EventController].
- add_css_class(css_class)[source]¶
- Parameters:
css_class (
str
) – The style class to add to self, without the leading ‘.’ used for notation of style classes
Adds a style class to self.
After calling this function, the widget’s style will match for css_class, according to CSS matching rules.
Use [method`Gtk`.Widget.remove_css_class] to remove the style again.
- add_mnemonic_label(label)[source]¶
- Parameters:
label (
Gtk.Widget
) – aGtkWidget
that acts as a mnemonic label for self
Adds a widget to the list of mnemonic labels for this widget.
See [method`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.
- add_tick_callback(callback, *user_data)[source]¶
- Parameters:
callback (
Gtk.TickCallback
) – function to call for updating animations
- Returns:
an id for the connection of this callback. Remove the callback by passing the id returned from this function to [method`Gtk`.Widget.remove_tick_callback]
- Return type:
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 [method`Gtk`.Widget.queue_resize] or [method`Gtk`.Widget.queue_draw] yourself.[method`Gdk`.FrameClock.get_frame_time] should generally be used for timing continuous animations and [method`Gdk`.FrameTimings.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 [signal`Gdk`.FrameClock::update] signal of
GdkFrameClock
, since you don’t have to worry about when aGdkFrameClock
is assigned to a widget.
- allocate(width, height, baseline, transform)[source]¶
- Parameters:
width (
int
) – New width of selfheight (
int
) – New height of selfbaseline (
int
) – New baseline of self, or -1transform (
Gsk.Transform
orNone
) – Transformation to be applied to self
This function is only used by
GtkWidget
subclasses, to assign a size, position and (optionally) baseline to their child widgets.In this function, the allocation and baseline may be adjusted. The given allocation will be forced to be bigger than the widget’s minimum size, as well as at least 0×0 in size.
For a version that does not take a transform, see [method`Gtk`.Widget.size_allocate].
- child_focus(direction)[source]¶
- Parameters:
direction (
Gtk.DirectionType
) – direction of focus movement- Returns:
True
if focus ended up inside self- Return type:
Called by widgets as the user moves around the window using keyboard shortcuts.
The direction argument indicates what kind of motion is taking place (up, down, left, right, tab forward, tab backward).
This function calls the [vfunc`Gtk`.Widget.focus] virtual function; widgets can override the virtual function in order to implement appropriate focus behavior.
The default
focus()
virtual function for a widget should returnTRUE
if moving in direction left the focus on a focusable location inside that widget, andFALSE
if moving in direction moved the focus outside the widget. When returningTRUE
, widgets normally call [method`Gtk`.Widget.grab_focus] to place the focus accordingly; when returningFALSE
, they don’t modify the current focus location.This function is used by custom widget implementations; if you’re writing an app, you’d use [method`Gtk`.Widget.grab_focus] to move the focus to a particular widget.
- compute_bounds(target)[source]¶
- Parameters:
target (
Gtk.Widget
) – theGtkWidget
- Returns:
True
if the bounds could be computed- out_bounds:
the rectangle taking the bounds
- Return type:
(
bool
, out_bounds:Graphene.Rect
)
Computes the bounds for self in the coordinate space of target.
The bounds of widget are (the bounding box of) the region that it is expected to draw in. See the coordinate system overview to learn more.
If the operation is successful,
True
is returned. If self has no bounds or the bounds cannot be expressed in target's coordinate space (for example if both widgets are in different windows),False
is returned and bounds is set to the zero rectangle.It is valid for self and target to be the same widget.
- compute_expand(orientation)[source]¶
- Parameters:
orientation (
Gtk.Orientation
) – expand direction- Returns:
whether widget tree rooted here should be expanded
- Return type:
Computes whether a container should give this widget extra space when possible.
Containers should check this, rather than looking at [method`Gtk`.Widget.get_hexpand] or [method`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.
- compute_point(target, point)[source]¶
- Parameters:
target (
Gtk.Widget
) – theGtkWidget
to transform intopoint (
Graphene.Point
) – a point in self's coordinate system
- Returns:
True
if the point could be determined,False
on failure. In this case, 0 is stored in out_point.- out_point:
Set to the corresponding coordinates in target's coordinate system
- Return type:
(
bool
, out_point:Graphene.Point
)
Translates the given point in self's coordinates to coordinates relative to target’s coordinate system.
In order to perform this operation, both widgets must share a common ancestor.
- compute_transform(target)[source]¶
- Parameters:
target (
Gtk.Widget
) – the target widget that the matrix will transform to- Returns:
True
if the transform could be computed,False
otherwise- out_transform:
location to store the final transformation
- Return type:
(
bool
, out_transform:Graphene.Matrix
)
Computes a matrix suitable to describe a transformation from self's coordinate system into target's coordinate system.
The transform can not be computed in certain cases, for example when self and target do not share a common ancestor. In that case out_transform gets set to the identity matrix.
To learn more about widget coordinate systems, see the coordinate system overview.
- contains(x, y)[source]¶
- Parameters:
- Returns:
True
if self contains (x, y).- Return type:
Tests if the point at (x, y) is contained in self.
The coordinates for (x, y) must be in widget coordinates, so (0, 0) is assumed to be the top left of self's content area.
- create_pango_context()[source]¶
- Returns:
the new
PangoContext
- Return type:
Creates a new
PangoContext
with the appropriate font map, font options, font description, and base direction for drawing text for this widget.See also [method`Gtk`.Widget.get_pango_context].
- create_pango_layout(text)[source]¶
- Parameters:
- Returns:
the new
PangoLayout
- Return type:
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 widgetPangoContext
is replaced. This can be tracked by listening to changes of the [property`Gtk`.Widget:root] property on the widget.
- dispose_template(widget_type)[source]¶
- Parameters:
widget_type (
GObject.GType
) – the type of the widget to finalize the template for
Clears the template children for the given widget.
This function is the opposite of [method`Gtk`.Widget.init_template], and it is used to clear all the template children from a widget instance. If you bound a template child to a field in the instance structure, or in the instance private data structure, the field will be set to
NULL
after this function returns.You should call this function inside the
GObjectClass.dispose()
implementation of any widget that calledgtk_widget_init_template()
. Typically, you will want to call this function last, right before chaining up to the parent type’s dispose implementation, e.g.```c static void some_widget_dispose (
GObject.Object
*gobject) { SomeWidget *self = SOME_WIDGET (gobject);// Clear the template data for SomeWidget
Gtk.Widget.dispose_template
(GTK_WIDGET (self), SOME_TYPE_WIDGET);G_OBJECT_CLASS (some_widget_parent_class)->dispose (gobject); } ```
New in version 4.8.
- drag_check_threshold(start_x, start_y, current_x, current_y)[source]¶
- Parameters:
- Returns:
True
if the drag threshold has been passed.- Return type:
Checks to see if a drag movement has passed the GTK drag threshold.
- error_bell()[source]¶
Notifies the user about an input-related error on this widget.
If the [property`Gtk`.Settings:gtk-error-bell] setting is
True
, it calls [method`Gdk`.Surface.beep], otherwise it does nothing.Note that the effect of [method`Gdk`.Surface.beep] can be configured in many ways, depending on the windowing backend and the desktop environment or window manager that is used.
- get_allocated_baseline()[source]¶
- Returns:
the baseline of the self, or -1 if none
- Return type:
Returns the baseline that has currently been allocated to self.
This function is intended to be used when implementing handlers for the ``GtkWidget``Class.snapshot() function, and when allocating child widgets in ``GtkWidget``Class.size_allocate().
Deprecated since version 4.12: Use [method`Gtk`.Widget.get_baseline] instead
- get_allocated_height()[source]¶
- Returns:
the height of the self
- Return type:
Returns the height that has currently been allocated to self.
To learn more about widget sizes, see the coordinate system overview.
Deprecated since version 4.12: Use [method`Gtk`.Widget.get_height] instead
- get_allocated_width()[source]¶
- Returns:
the width of the self
- Return type:
Returns the width that has currently been allocated to self.
To learn more about widget sizes, see the coordinate system overview.
Deprecated since version 4.12: Use [method`Gtk`.Widget.get_width] instead
- get_allocation()[source]¶
- Returns:
a pointer to a
GtkAllocation
to copy to- Return type:
allocation:
Gdk.Rectangle
Retrieves the widget’s allocation.
Note, when implementing a layout container: a widget’s allocation will be its “adjusted” allocation, that is, the widget’s parent typically calls [method`Gtk`.Widget.size_allocate] with an allocation, and that allocation is then adjusted (to handle margin and alignment for example) before assignment to the widget. [method`Gtk`.Widget.get_allocation] returns the adjusted allocation that was actually assigned to the widget. The adjusted allocation is guaranteed to be completely contained within the [method`Gtk`.Widget.size_allocate] allocation, however.
So a layout container is guaranteed that its children stay inside the assigned bounds, but not that they have exactly the bounds the container assigned.
Deprecated since version 4.12: Use [method`Gtk`.Widget.compute_bounds], [method`Gtk`.Widget.get_width] or [method`Gtk`.Widget.get_height] instead.
- get_ancestor(widget_type)[source]¶
- Parameters:
widget_type (
GObject.GType
) – ancestor type- Returns:
the ancestor widget
- Return type:
Gtk.Widget
orNone
Gets the first ancestor of self with type widget_type.
For example,
gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)
gets the firstGtkBox
that’s an ancestor of self. No reference will be added to the returned widget; it should not be unreferenced.Note that unlike [method`Gtk`.Widget.is_ancestor], this function considers self to be an ancestor of itself.
- get_baseline()[source]¶
- Returns:
the baseline of the self, or -1 if none
- Return type:
Returns the baseline that has currently been allocated to self.
This function is intended to be used when implementing handlers for the ``GtkWidget``Class.snapshot() function, and when allocating child widgets in ``GtkWidget``Class.size_allocate().
New in version 4.12.
- get_can_focus()[source]¶
-
Determines whether the input focus can enter self or any of its children.
See [method`Gtk`.Widget.set_focusable].
- get_child_visible()[source]¶
-
Gets the value set with
Gtk.Widget.set_child_visible
().If you feel a need to use this function, your code probably needs reorganization.
This function is only useful for container implementations and should never be called by an application.
- get_clipboard()[source]¶
- Returns:
the appropriate clipboard object
- Return type:
Gets the clipboard object for self.
This is a utility function to get the clipboard object for the
GdkDisplay
that self is using.Note that this function always works, even when self is not realized yet.
- get_color()[source]¶
- Returns:
return location for the color
- Return type:
color:
Gdk.RGBA
Gets the current foreground color for the widget’s CSS style.
This function should only be used in snapshot implementations that need to do custom drawing with the foreground color.
New in version 4.10.
- get_css_classes()[source]¶
- Returns:
a
None
-terminated list of css classes currently applied to self. The returned list must freed usingGLib.strfreev
().- Return type:
[
str
]
Returns the list of style classes applied to self.
- get_css_name()[source]¶
- Returns:
the CSS name
- Return type:
Returns the CSS name that is used for self.
- get_cursor()[source]¶
- Returns:
the cursor currently in use or
None
if the cursor is inherited- Return type:
Gdk.Cursor
orNone
Queries the cursor set on self.
See [method`Gtk`.Widget.set_cursor] for details.
- get_direction()[source]¶
- Returns:
the reading direction for the widget.
- Return type:
Gets the reading direction for a particular widget.
See [method`Gtk`.Widget.set_direction].
- get_display()[source]¶
- Returns:
the
GdkDisplay
for the toplevel for this widget.- Return type:
Get the
GdkDisplay
for the toplevel window associated with this widget.This function can only be called after the widget has been added to a widget hierarchy with a
GtkWindow
at the top.In general, you should only create display specific resources when a widget has been realized, and you should free those resources when the widget is unrealized.
- get_first_child()[source]¶
- Returns:
The widget’s first child
- Return type:
Gtk.Widget
orNone
Returns the widget’s first child.
This API is primarily meant for widget implementations.
- get_focus_child()[source]¶
- Returns:
The current focus child of self
- Return type:
Gtk.Widget
orNone
Returns the current focus child of self.
- get_focus_on_click()[source]¶
-
Returns whether the widget should grab focus when it is clicked with the mouse.
See [method`Gtk`.Widget.set_focus_on_click].
- get_focusable()[source]¶
-
Determines whether self can own the input focus.
See [method`Gtk`.Widget.set_focusable].
- get_font_map()[source]¶
- Returns:
A
PangoFontMap
- Return type:
Gets the font map of self.
See [method`Gtk`.Widget.set_font_map].
- get_font_options()[source]¶
- Returns:
the
cairo_font_options_t
of widget- Return type:
Returns the
cairo_font_options_t
of widget.Seee [method`Gtk`.Widget.set_font_options].
- get_frame_clock()[source]¶
- Returns:
a
GdkFrameClock
- Return type:
Obtains the frame clock for a widget.
The frame clock is a global “ticker” that can be used to drive animations and repaints. The most common reason to get the frame clock is to call [method`Gdk`.FrameClock.get_frame_time], in order to get a time to use for animating. For example you might record the start of the animation with an initial value from [method`Gdk`.FrameClock.get_frame_time], and then update the animation by calling [method`Gdk`.FrameClock.get_frame_time] again during each repaint.
[method`Gdk`.FrameClock.request_phase] will result in a new frame on the clock, but won’t necessarily repaint any widgets. To repaint a widget, you have to use [method`Gtk`.Widget.queue_draw] which invalidates the widget (thus scheduling it to receive a draw on the next frame).
Gtk.Widget.queue_draw
() will also end up requesting a frame on the appropriate frame clock.A widget’s frame clock will not change while the widget is mapped. Reparenting a widget (which implies a temporary unmap) can change the widget’s frame clock.
Unrealized widgets do not have a frame clock.
- get_halign()[source]¶
- Returns:
the horizontal alignment of self
- Return type:
Gets the horizontal alignment of self.
For backwards compatibility reasons this method will never return one of the baseline alignments, but instead it will convert it to
GTK_ALIGN_FILL
orGTK_ALIGN_CENTER
.Baselines are not supported for horizontal alignment.
- get_has_tooltip()[source]¶
- Returns:
current value of
has-tooltip
on self.- Return type:
Returns the current value of the
has-tooltip
property.
- get_height()[source]¶
- Returns:
The height of self
- Return type:
Returns the content height of the widget.
This function returns the height passed to its size-allocate implementation, which is the height you should be using in [vfunc`Gtk`.Widget.snapshot].
For pointer events, see [method`Gtk`.Widget.contains].
To learn more about widget sizes, see the coordinate system overview.
- get_hexpand()[source]¶
- Returns:
whether hexpand flag is set
- Return type:
Gets whether the widget would like any available extra horizontal space.
When a user resizes a
GtkWindow
, widgets with expand=:obj:True generally receive the extra space. For example, a list or scrollable area or document in your window would often be set to expand.Containers should use [method`Gtk`.Widget.compute_expand] rather than this function, to see whether a widget, or any of its children, has the expand flag set. If any child of a widget wants to expand, the parent may ask to expand also.
This function only looks at the widget’s own hexpand flag, rather than computing whether the entire widget tree rooted at this widget wants to expand.
- get_hexpand_set()[source]¶
- Returns:
whether hexpand has been explicitly set
- Return type:
Gets whether
Gtk.Widget.set_hexpand
() has been used to explicitly set the expand flag on this widget.If [property`Gtk`.Widget:hexpand] property is set, then it overrides any computed expand value based on child widgets. If
hexpand
is not set, then the expand value depends on whether any children of the widget would like to expand.There are few reasons to use this function, but it’s here for completeness and consistency.
- get_last_child()[source]¶
- Returns:
The widget’s last child
- Return type:
Gtk.Widget
orNone
Returns the widget’s last child.
This API is primarily meant for widget implementations.
- get_layout_manager()[source]¶
- Returns:
a
GtkLayoutManager
- Return type:
Retrieves the layout manager used by self.
See [method`Gtk`.Widget.set_layout_manager].
- get_margin_bottom()[source]¶
- Returns:
The bottom margin of self
- Return type:
Gets the bottom margin of self.
- get_margin_start()[source]¶
- Returns:
The start margin of self
- Return type:
Gets the start margin of self.
- get_name()[source]¶
- Returns:
name of the widget. This string is owned by GTK and should not be modified or freed
- Return type:
Retrieves the name of a widget.
See [method`Gtk`.Widget.set_name] for the significance of widget names.
- get_native()[source]¶
- Returns:
the
GtkNative
ancestor of self- Return type:
Gtk.Native
orNone
Returns the nearest
GtkNative
ancestor of self.This function will return
None
if the widget is not contained inside a widget tree with a native ancestor.GtkNative
widgets will return themselves here.
- get_next_sibling()[source]¶
- Returns:
The widget’s next sibling
- Return type:
Gtk.Widget
orNone
Returns the widget’s next sibling.
This API is primarily meant for widget implementations.
- get_opacity()[source]¶
- Returns:
the requested opacity for this widget.
- Return type:
#Fetches the requested opacity for this widget.
See [method`Gtk`.Widget.set_opacity].
- get_overflow()[source]¶
- Returns:
The widget’s overflow.
- Return type:
Returns the widget’s overflow value.
- get_pango_context()[source]¶
- Returns:
the
PangoContext
for the widget.- Return type:
Gets a
PangoContext
with the appropriate font map, font description, and base direction for this widget.Unlike the context returned by [method`Gtk`.Widget.create_pango_context], this context is owned by the widget (it can be used until the screen for the widget changes or the widget is removed from its toplevel), and will be updated to match any changes to the widget’s attributes. This can be tracked by listening to changes of the [property`Gtk`.Widget:root] property on the widget.
- get_parent()[source]¶
- Returns:
the parent widget of self
- Return type:
Gtk.Widget
orNone
Returns the parent widget of self.
- get_preferred_size()[source]¶
- Returns:
- minimum_size:
location for storing the minimum size
- natural_size:
location for storing the natural size
- Return type:
(minimum_size:
Gtk.Requisition
, natural_size:Gtk.Requisition
)
Retrieves the minimum and natural size of a widget, taking into account the widget’s preference for height-for-width management.
This is used to retrieve a suitable size by container widgets which do not impose any restrictions on the child placement. It can be used to deduce toplevel window and menu sizes as well as child widgets in free-form containers such as
GtkFixed
.Handle with care. Note that the natural height of a height-for-width widget will generally be a smaller size than the minimum height, since the required height for the natural width is generally smaller than the required height for the minimum width.
Use [id`gtk_widget_measure`] if you want to support baseline alignment.
- get_prev_sibling()[source]¶
- Returns:
The widget’s previous sibling
- Return type:
Gtk.Widget
orNone
Returns the widget’s previous sibling.
This API is primarily meant for widget implementations.
- get_primary_clipboard()[source]¶
- Returns:
the appropriate clipboard object
- Return type:
Gets the primary clipboard of self.
This is a utility function to get the primary clipboard object for the
GdkDisplay
that self is using.Note that this function always works, even when self is not realized yet.
- get_receives_default()[source]¶
-
Determines whether self is always treated as the default widget within its toplevel when it has the focus, even if another widget is the default.
See [method`Gtk`.Widget.set_receives_default].
- get_request_mode()[source]¶
- Returns:
The
GtkSizeRequestMode
preferred by self.- Return type:
Gets whether the widget prefers a height-for-width layout or a width-for-height layout.
Single-child widgets generally propagate the preference of their child, more complex widgets need to request something either in context of their children or in context of their allocation capabilities.
- get_root()[source]¶
-
Returns the
GtkRoot
widget of self.This function will return
None
if the widget is not contained inside a widget tree with a root widget.GtkRoot
widgets will return themselves here.
- get_scale_factor()[source]¶
- Returns:
the scale factor for self
- Return type:
Retrieves the internal scale factor that maps from window coordinates to the actual device pixels.
On traditional systems this is 1, on high density outputs, it can be a higher value (typically 2).
See [method`Gdk`.Surface.get_scale_factor].
- get_sensitive()[source]¶
-
Returns the widget’s sensitivity.
This function returns the value that has been set using [method`Gtk`.Widget.set_sensitive]).
The effective sensitivity of a widget is however determined by both its own and its parent widget’s sensitivity. See [method`Gtk`.Widget.is_sensitive].
- get_settings()[source]¶
- Returns:
the relevant
GtkSettings
object- Return type:
Gets the settings object holding the settings used for this widget.
Note that this function can only be called when the
GtkWidget
is attached to a toplevel, since the settings object is specific to a particularGdkDisplay
. If you want to monitor the widget for changes in its settings, connect to thenotify::display
signal.
- get_size(orientation)[source]¶
- Parameters:
orientation (
Gtk.Orientation
) – the orientation to query- Returns:
The size of self in orientation.
- Return type:
Returns the content width or height of the widget.
Which dimension is returned depends on orientation.
This is equivalent to calling [method`Gtk`.Widget.get_width] for
Gtk.Orientation.HORIZONTAL
or [method`Gtk`.Widget.get_height] forGtk.Orientation.VERTICAL
, but can be used when writing orientation-independent code, such as when implementing [iface`Gtk`.Orientable] widgets.To learn more about widget sizes, see the coordinate system overview.
- get_size_request()[source]¶
- Returns:
- width:
return location for width
- height:
return location for height
- Return type:
Gets the size request that was explicitly set for the widget using
Gtk.Widget.set_size_request
().A value of -1 stored in width or height indicates that that dimension has not been set explicitly and the natural requisition of the widget will be used instead. See [method`Gtk`.Widget.set_size_request]. To get the size a widget will actually request, call [method`Gtk`.Widget.measure] instead of this function.
- get_state_flags()[source]¶
- Returns:
The state flags for widget
- Return type:
Returns the widget state as a flag set.
It is worth mentioning that the effective
Gtk.StateFlags.INSENSITIVE
state will be returned, that is, also based on parent insensitivity, even if self itself is sensitive.Also note that if you are looking for a way to obtain the [flags`Gtk`.StateFlags] to pass to a [class`Gtk`.StyleContext] method, you should look at [method`Gtk`.StyleContext.get_state].
- get_style_context()[source]¶
- Returns:
the widget’s
GtkStyleContext
- Return type:
Returns the style context associated to self.
The returned object is guaranteed to be the same for the lifetime of self.
Deprecated since version 4.10: Style contexts will be removed in GTK 5
- get_template_child(widget_type, name)[source]¶
- Parameters:
widget_type (
GObject.GType
) – TheGType
to get a template child forname (
str
) – The “id” of the child defined in the template XML
- Returns:
The object built in the template XML with the id name
- Return type:
Fetch an object build from the template XML for widget_type in this self instance.
This will only report children which were previously declared with [method`Gtk`.WidgetClass.bind_template_child_full] or one of its variants.
This function is only meant to be called for code which is private to the widget_type which declared the child and is meant for language bindings which cannot easily make use of the
GObject.Object
structure offsets.
- get_tooltip_markup()[source]¶
-
Gets the contents of the tooltip for self.
If the tooltip has not been set using [method`Gtk`.Widget.set_tooltip_markup], this function returns
None
.
- get_tooltip_text()[source]¶
-
Gets the contents of the tooltip for self.
If the self's tooltip was set using [method`Gtk`.Widget.set_tooltip_markup], this function will return the escaped text.
- get_valign()[source]¶
- Returns:
the vertical alignment of self
- Return type:
Gets the vertical alignment of self.
- get_vexpand()[source]¶
- Returns:
whether vexpand flag is set
- Return type:
Gets whether the widget would like any available extra vertical space.
See [method`Gtk`.Widget.get_hexpand] for more detail.
- get_vexpand_set()[source]¶
- Returns:
whether vexpand has been explicitly set
- Return type:
Gets whether
Gtk.Widget.set_vexpand
() has been used to explicitly set the expand flag on this widget.See [method`Gtk`.Widget.get_hexpand_set] for more detail.
- get_visible()[source]¶
-
Determines whether the widget is visible.
If you want to take into account whether the widget’s parent is also marked as visible, use [method`Gtk`.Widget.is_visible] instead.
This function does not check if the widget is obscured in any way.
See [method`Gtk`.Widget.set_visible].
- get_width()[source]¶
- Returns:
The width of self
- Return type:
Returns the content width of the widget.
This function returns the width passed to its size-allocate implementation, which is the width you should be using in [vfunc`Gtk`.Widget.snapshot].
For pointer events, see [method`Gtk`.Widget.contains].
To learn more about widget sizes, see the coordinate system overview.
- grab_focus()[source]¶
-
Causes self to have the keyboard focus for the
GtkWindow
it’s inside.If self is not focusable, or its [vfunc`Gtk`.Widget.grab_focus] implementation cannot transfer the focus to a descendant of self that is focusable, it will not take focus and
False
will be returned.Calling [method`Gtk`.Widget.grab_focus] on an already focused widget is allowed, should not have an effect, and return
True
.
- has_css_class(css_class)[source]¶
- Parameters:
css_class (
str
) – A style class, without the leading ‘.’ used for notation of style classes- Returns:
True
if css_class is currently applied to self,False
otherwise.- Return type:
Returns whether css_class is currently applied to self.
- has_default()[source]¶
- Returns:
True
if self is the current default widget within its toplevel,False
otherwise- Return type:
Determines whether self is the current default widget within its toplevel.
- has_focus()[source]¶
-
Determines if the widget has the global input focus.
See [method`Gtk`.Widget.is_focus] for the difference between having the global input focus, and only having the focus within a toplevel.
- has_visible_focus()[source]¶
-
Determines if the widget should show a visible indication that it has the global input focus.
This is a convenience function that takes into account whether focus indication should currently be shown in the toplevel window of self. See [method`Gtk`.Window.get_focus_visible] for more information about focus indication.
To find out if the widget has the global input focus, use [method`Gtk`.Widget.has_focus].
- hide()[source]¶
Reverses the effects of
Gtk.Widget.show
().This is causing the widget to be hidden (invisible to the user).
Deprecated since version 4.10: Use [method`Gtk`.Widget.set_visible] instead
- in_destruction()[source]¶
-
Returns whether the widget is currently being destroyed.
This information can sometimes be used to avoid doing unnecessary work.
- init_template()[source]¶
Creates and initializes child widgets defined in templates.
This function must be called in the instance initializer for any class which assigned itself a template using [method`Gtk`.WidgetClass.set_template].
It is important to call this function in the instance initializer of a
GtkWidget
subclass and not inGObject.constructed()
orGObject.constructor()
for two reasons:derived widgets will assume that the composite widgets defined by its parent classes have been created in their relative instance initializers
when calling
g_object_new()
on a widget with composite templates, it’s important to build the composite widgets before the construct properties are set. Properties passed tog_object_new()
should take precedence over properties set in the private template XML
A good rule of thumb is to call this function as the first thing in an instance initialization function.
- insert_action_group(name, group)[source]¶
- Parameters:
name (
str
) – the prefix for actions in groupgroup (
Gio.ActionGroup
orNone
) – aGActionGroup
, orNone
to remove the previously inserted group for name
Inserts group into self.
Children of self that implement [iface`Gtk`.Actionable] can then be associated with actions in group by setting their “action-name” to prefix.``action-name``.
Note that inheritance is defined for individual actions. I.e. even if you insert a group with prefix prefix, actions with the same prefix will still be inherited from the parent, unless the group contains an action with the same name.
If group is
None
, a previously inserted group for name is removed from self.
- insert_after(parent, previous_sibling)[source]¶
- Parameters:
parent (
Gtk.Widget
) – the parentGtkWidget
to insert self intoprevious_sibling (
Gtk.Widget
orNone
) – the new previous sibling of self
Inserts self into the child widget list of parent.
It will be placed after previous_sibling, or at the beginning if previous_sibling is
None
.After calling this function,
gtk_widget_get_prev_sibling(widget)
will return previous_sibling.If parent is already set as the parent widget of self, this function can also be used to reorder self in the child widget list of parent.
This API is primarily meant for widget implementations; if you are just using a widget, you *must* use its own API for adding children.
- insert_before(parent, next_sibling)[source]¶
- Parameters:
parent (
Gtk.Widget
) – the parentGtkWidget
to insert self intonext_sibling (
Gtk.Widget
orNone
) – the new next sibling of self
Inserts self into the child widget list of parent.
It will be placed before next_sibling, or at the end if next_sibling is
None
.After calling this function,
gtk_widget_get_next_sibling(widget)
will return next_sibling.If parent is already set as the parent widget of self, this function can also be used to reorder self in the child widget list of parent.
This API is primarily meant for widget implementations; if you are just using a widget, you *must* use its own API for adding children.
- is_ancestor(ancestor)[source]¶
- Parameters:
ancestor (
Gtk.Widget
) – anotherGtkWidget
- Returns:
True
if ancestor contains self as a child, grandchild, great grandchild, etc.- Return type:
Determines whether self is somewhere inside ancestor, possibly with intermediate containers.
- is_drawable()[source]¶
-
Determines whether self can be drawn to.
A widget can be drawn if it is mapped and visible.
- is_focus()[source]¶
-
Determines if the widget is the focus widget within its toplevel.
This does not mean that the [property`Gtk`.Widget:has-focus] property is necessarily set; [property`Gtk`.Widget:has-focus] will only be set if the toplevel widget additionally has the global input focus.
- is_sensitive()[source]¶
-
Returns the widget’s effective sensitivity.
This means it is sensitive itself and also its parent widget is sensitive.
- is_visible()[source]¶
-
Determines whether the widget and all its parents are marked as visible.
This function does not check if the widget is obscured in any way.
See also [method`Gtk`.Widget.get_visible] and [method`Gtk`.Widget.set_visible].
- Parameters:
direction (
Gtk.DirectionType
) – direction of focus movement- Returns:
True
if stopping keyboard navigation is fine,False
if the emitting widget should try to handle the keyboard navigation attempt in its parent container(s).- Return type:
Emits the
::keynav-failed
signal on the widget.This function should be called whenever keyboard navigation within a single widget hits a boundary.
The return value of this function should be interpreted in a way similar to the return value of [method`Gtk`.Widget.child_focus]. When
True
is returned, stay in the widget, the failed keyboard navigation is OK and/or there is nowhere we can/should move the focus to. WhenFalse
is returned, the caller should continue with keyboard navigation outside the widget, e.g. by calling [method`Gtk`.Widget.child_focus] on the widget’s toplevel.The default [signal`Gtk`.Widget::keynav-failed] handler returns
False
forGtk.DirectionType.TAB_FORWARD
andGtk.DirectionType.TAB_BACKWARD
. For the other values ofGtkDirectionType
it returnsTrue
.Whenever the default handler returns
True
, it also calls [method`Gtk`.Widget.error_bell] to notify the user of the failed keyboard navigation.A use case for providing an own implementation of
::keynav-failed
(either by connecting to it or by overriding it) would be a row of [class`Gtk`.Entry] widgets where the user should be able to navigate the entire row with the cursor keys, as e.g. known from user interfaces that require entering license keys.
- list_mnemonic_labels()[source]¶
- Returns:
the list of mnemonic labels; free this list with g_list_free() when you are done with it.
- Return type:
Returns the widgets for which this widget is the target of a mnemonic.
Typically, these widgets will be labels. See, for example, [method`Gtk`.Label.set_mnemonic_widget].
The widgets in the list are not individually referenced. If you want to iterate through the list and perform actions involving callbacks that might destroy the widgets, you must call
g_list_foreach (result, (GFunc)g_object_ref, NULL)
first, and then unref all the widgets afterwards.
- map()[source]¶
Causes a widget to be mapped if it isn’t already.
This function is only for use in widget implementations.
- measure(orientation, for_size)[source]¶
- Parameters:
orientation (
Gtk.Orientation
) – the orientation to measurefor_size (
int
) – Size for the opposite of orientation, i.e. if orientation isGtk.Orientation.HORIZONTAL
, this is the height the widget should be measured with. TheGtk.Orientation.VERTICAL
case is analogous. This way, both height-for-width and width-for-height requests can be implemented. If no size is known, -1 can be passed.
- Returns:
- minimum:
location to store the minimum size
- natural:
location to store the natural size
- minimum_baseline:
location to store the baseline position for the minimum size, or -1 to report no baseline
- natural_baseline:
location to store the baseline position for the natural size, or -1 to report no baseline
- Return type:
(minimum:
int
, natural:int
, minimum_baseline:int
, natural_baseline:int
)
Measures self in the orientation orientation and for the given for_size.
As an example, if orientation is
Gtk.Orientation.HORIZONTAL
and for_size is 300, this functions will compute the minimum and natural width of self if it is allocated at a height of 300 pixels.See GtkWidget’s geometry management section for a more details on implementing
GtkWidgetClass.measure()
.
- mnemonic_activate(group_cycling)[source]¶
- Parameters:
group_cycling (
bool
) –True
if there are other widgets with the same mnemonic- Returns:
True
if the signal has been handled- Return type:
Emits the
::mnemonic-activate
signal.See [signal`Gtk`.Widget::mnemonic-activate].
- observe_children()[source]¶
- Returns:
a
GListModel
tracking self's children- Return type:
Returns a
GListModel
to track the children of self.Calling this function will enable extra internal bookkeeping to track children and emit signals on the returned listmodel. It may slow down operations a lot.
Applications should try hard to avoid calling this function because of the slowdowns.
- observe_controllers()[source]¶
- Returns:
a
GListModel
tracking self's controllers- Return type:
Returns a
GListModel
to track the [class`Gtk`.EventController]s of self.Calling this function will enable extra internal bookkeeping to track controllers and emit signals on the returned listmodel. It may slow down operations a lot.
Applications should try hard to avoid calling this function because of the slowdowns.
- pick(x, y, flags)[source]¶
- Parameters:
x (
float
) – X coordinate to test, relative to self's originy (
float
) – Y coordinate to test, relative to self's originflags (
Gtk.PickFlags
) – Flags to influence what is picked
- Returns:
The widget descendant at the given point
- Return type:
Gtk.Widget
orNone
Finds the descendant of self closest to the point (x, y).
The point must be given in widget coordinates, so (0, 0) is assumed to be the top left of self's content area.
Usually widgets will return
None
if the given coordinate is not contained in self checked via [method`Gtk`.Widget.contains]. Otherwise they will recursively try to find a child that does not returnNone
. Widgets are however free to customize their picking algorithm.This function is used on the toplevel to determine the widget below the mouse cursor for purposes of hover highlighting and delivering events.
- queue_allocate()[source]¶
Flags the widget for a rerun of the [vfunc`Gtk`.Widget.size_allocate] function.
Use this function instead of [method`Gtk`.Widget.queue_resize] when the self's size request didn’t change but it wants to reposition its contents.
An example user of this function is [method`Gtk`.Widget.set_halign].
This function is only for use in widget implementations.
- queue_draw()[source]¶
Schedules this widget to be redrawn in the paint phase of the current or the next frame.
This means self's [vfunc`Gtk`.Widget.snapshot] implementation will be called.
- queue_resize()[source]¶
Flags a widget to have its size renegotiated.
This should be called when a widget for some reason has a new size request. For example, when you change the text in a [class`Gtk`.Label], the label queues a resize to ensure there’s enough space for the new text.
Note that you cannot call
Gtk.Widget.queue_resize
() on a widget from inside its implementation of the [vfunc`Gtk`.Widget.size_allocate] virtual method. Calls toGtk.Widget.queue_resize
() from inside [vfunc`Gtk`.Widget.size_allocate] will be silently ignored.This function is only for use in widget implementations.
- realize()[source]¶
Creates the GDK resources associated with a widget.
Normally realization happens implicitly; if you show a widget and all its parent containers, then the widget will be realized and mapped automatically.
Realizing a widget requires all the widget’s parent widgets to be realized; calling this function realizes the widget’s parents in addition to self itself. If a widget is not yet inside a toplevel window when you realize it, bad things will happen.
This function is primarily used in widget implementations, and isn’t very useful otherwise. Many times when you think you might need it, a better approach is to connect to a signal that will be called after the widget is realized automatically, such as [signal`Gtk`.Widget::realize].
- remove_controller(controller)[source]¶
- Parameters:
controller (
Gtk.EventController
) – aGtkEventController
Removes controller from self, so that it doesn’t process events anymore.
It should not be used again.
Widgets will remove all event controllers automatically when they are destroyed, there is normally no need to call this function.
- remove_css_class(css_class)[source]¶
- Parameters:
css_class (
str
) – The style class to remove from self, without the leading ‘.’ used for notation of style classes
Removes a style from self.
After this, the style of self will stop matching for css_class.
- remove_mnemonic_label(label)[source]¶
- Parameters:
label (
Gtk.Widget
) – aGtkWidget
that was previously set as a mnemonic label for self with [method`Gtk`.Widget.add_mnemonic_label]
Removes a widget from the list of mnemonic labels for this widget.
See [method`Gtk`.Widget.list_mnemonic_labels]. The widget must have previously been added to the list with [method`Gtk`.Widget.add_mnemonic_label].
- remove_tick_callback(id)[source]¶
- Parameters:
id (
int
) – an id returned by [method`Gtk`.Widget.add_tick_callback]
Removes a tick callback previously registered with
Gtk.Widget.add_tick_callback
().
- set_can_focus(can_focus)[source]¶
- Parameters:
can_focus (
bool
) – whether or not the input focus can enter the widget or any of its children
Specifies whether the input focus can enter the widget or any of its children.
Applications should set can_focus to
False
to mark a widget as for pointer/touch use only.Note that having can_focus be
True
is only one of the necessary conditions for being focusable. A widget must also be sensitive and focusable and not have an ancestor that is marked as not can-focus in order to receive input focus.See [method`Gtk`.Widget.grab_focus] for actually setting the input focus on a widget.
- set_can_target(can_target)[source]¶
- Parameters:
can_target (
bool
) – whether this widget should be able to receive pointer events
Sets whether self can be the target of pointer events.
- set_child_visible(child_visible)[source]¶
-
Sets whether self should be mapped along with its parent.
The child visibility can be set for widget before it is added to a container with [method`Gtk`.Widget.set_parent], to avoid mapping children unnecessary before immediately unmapping them. However it will be reset to its default state of
True
when the widget is removed from a container.Note that changing the child visibility of a widget does not queue a resize on the widget. Most of the time, the size of a widget is computed from all visible children, whether or not they are mapped. If this is not the case, the container can queue a resize itself.
This function is only useful for container implementations and should never be called by an application.
- set_css_classes(classes)[source]¶
-
Clear all style classes applied to self and replace them with classes.
- set_cursor(cursor)[source]¶
- Parameters:
cursor (
Gdk.Cursor
orNone
) – the new cursor
Sets the cursor to be shown when pointer devices point towards self.
If the cursor is
None
, self will use the cursor inherited from the parent widget.
- set_cursor_from_name(name)[source]¶
-
Sets a named cursor to be shown when pointer devices point towards self.
This is a utility function that creates a cursor via [ctor`Gdk`.Cursor.new_from_name] and then sets it on self with [method`Gtk`.Widget.set_cursor]. See those functions for details.
On top of that, this function allows name to be
None
, which will do the same as calling [method`Gtk`.Widget.set_cursor] with aNone
cursor.
- set_direction(dir)[source]¶
- Parameters:
dir (
Gtk.TextDirection
) – the new direction
Sets the reading direction on a particular widget.
This direction controls the primary direction for widgets containing text, and also the direction in which the children of a container are packed. The ability to set the direction is present in order so that correct localization into languages with right-to-left reading directions can be done. Generally, applications will let the default reading direction present, except for containers where the containers are arranged in an order that is explicitly visual rather than logical (such as buttons for text justification).
If the direction is set to
Gtk.TextDirection.NONE
, then the value set by [func`Gtk`.Widget.set_default_direction] will be used.
- set_focus_child(child)[source]¶
- Parameters:
child (
Gtk.Widget
orNone
) – a direct child widget of self orNone
to unset the focus child of self
Set child as the current focus child of self.
This function is only suitable for widget implementations. If you want a certain widget to get the input focus, call [method`Gtk`.Widget.grab_focus] on it.
- set_focus_on_click(focus_on_click)[source]¶
- Parameters:
focus_on_click (
bool
) – whether the widget should grab focus when clicked with the mouse
Sets whether the widget should 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.
- set_focusable(focusable)[source]¶
- Parameters:
focusable (
bool
) – whether or not self can own the input focus
Specifies whether self can own the input focus.
Widget implementations should set focusable to
True
in their init() function if they want to receive keyboard input.Note that having focusable be
True
is only one of the necessary conditions for being focusable. A widget must also be sensitive and can-focus and not have an ancestor that is marked as not can-focus in order to receive input focus.See [method`Gtk`.Widget.grab_focus] for actually setting the input focus on a widget.
- set_font_map(font_map)[source]¶
- Parameters:
font_map (
Pango.FontMap
orNone
) – aPangoFontMap
, orNone
to unset any previously set font map
Sets the font map to use for Pango rendering.
The font map is the object that is used to look up fonts. Setting a custom font map can be useful in special situations, e.g. when you need to add application-specific fonts to the set of available fonts.
When not set, the widget will inherit the font map from its parent.
- set_font_options(options)[source]¶
- Parameters:
options (
cairo.FontOptions
orNone
) – acairo_font_options_t
to unset any previously set default font options
Sets the
cairo_font_options_t
used for Pango rendering in this widget.When not set, the default font options for the
GdkDisplay
will be used.
- set_halign(align)[source]¶
- Parameters:
align (
Gtk.Align
) – the horizontal alignment
Sets the horizontal alignment of self.
- set_has_tooltip(has_tooltip)[source]¶
- Parameters:
has_tooltip (
bool
) – whether or not self has a tooltip.
Sets the
has-tooltip
property on self to has_tooltip.
- set_hexpand(expand)[source]¶
- Parameters:
expand (
bool
) – whether to expand
Sets whether the widget would like any available extra horizontal space.
When a user resizes a
GtkWindow
, widgets with expand=:obj:True generally receive the extra space. For example, a list or scrollable area or document in your window would often be set to expand.Call this function to set the expand flag if you would like your widget to become larger horizontally when the window has extra room.
By default, widgets automatically expand if any of their children want to expand. (To see if a widget will automatically expand given its current children and state, call [method`Gtk`.Widget.compute_expand]. A container can decide how the expandability of children affects the expansion of the container by overriding the compute_expand virtual method on
GtkWidget
.).Setting hexpand explicitly with this function will override the automatic expand behavior.
This function forces the widget to expand or not to expand, regardless of children. The override occurs because [method`Gtk`.Widget.set_hexpand] sets the hexpand-set property (see [method`Gtk`.Widget.set_hexpand_set]) which causes the widget’s hexpand value to be used, rather than looking at children and widget state.
- set_hexpand_set(set)[source]¶
- Parameters:
set (
bool
) – value for hexpand-set property
Sets whether the hexpand flag will be used.
The [property`Gtk`.Widget:hexpand-set] property will be set automatically when you call [method`Gtk`.Widget.set_hexpand] to set hexpand, so the most likely reason to use this function would be to unset an explicit expand flag.
If hexpand is set, then it overrides any computed expand value based on child widgets. If hexpand is not set, then the expand value depends on whether any children of the widget would like to expand.
There are few reasons to use this function, but it’s here for completeness and consistency.
- set_layout_manager(layout_manager)[source]¶
- Parameters:
layout_manager (
Gtk.LayoutManager
orNone
) – aGtkLayoutManager
Sets the layout manager delegate instance that provides an implementation for measuring and allocating the children of self.
- set_margin_bottom(margin)[source]¶
- Parameters:
margin (
int
) – the bottom margin
Sets the bottom margin of self.
- set_margin_end(margin)[source]¶
- Parameters:
margin (
int
) – the end margin
Sets the end margin of self.
- set_margin_start(margin)[source]¶
- Parameters:
margin (
int
) – the start margin
Sets the start margin of self.
- set_margin_top(margin)[source]¶
- Parameters:
margin (
int
) – the top margin
Sets the top margin of self.
- set_name(name)[source]¶
- Parameters:
name (
str
) – name for the widget
Sets a widgets name.
Setting a name allows you to refer to the widget from a CSS file. You can apply a style to widgets with a particular name in the CSS file. See the documentation for the CSS syntax (on the same page as the docs for [class`Gtk`.StyleContext].
Note that the CSS syntax has certain special characters to delimit and represent elements in a selector (period, #, >, *…), so using these will make your widget impossible to match by name. Any combination of alphanumeric symbols, dashes and underscores will suffice.
- set_opacity(opacity)[source]¶
- Parameters:
opacity (
float
) – desired opacity, between 0 and 1
Request the self to be rendered partially transparent.
An opacity of 0 is fully transparent and an opacity of 1 is fully opaque.
Opacity works on both toplevel widgets and child widgets, although there are some limitations: For toplevel widgets, applying opacity depends on the capabilities of the windowing system. On X11, this has any effect only on X displays with a compositing manager, see
Gdk.Display.is_composited
(). On Windows and Wayland it should always work, although setting a window’s opacity after the window has been shown may cause some flicker.Note that the opacity is inherited through inclusion — if you set a toplevel to be partially translucent, all of its content will appear translucent, since it is ultimatively rendered on that toplevel. The opacity value itself is not inherited by child widgets (since that would make widgets deeper in the hierarchy progressively more translucent). As a consequence, [class`Gtk`.Popover]s and other [iface`Gtk`.Native] widgets with their own surface will use their own opacity value, and thus by default appear non-translucent, even if they are attached to a toplevel that is translucent.
- set_overflow(overflow)[source]¶
- Parameters:
overflow (
Gtk.Overflow
) – desired overflow
Sets how self treats content that is drawn outside the widget’s content area.
See the definition of [enum`Gtk`.Overflow] for details.
This setting is provided for widget implementations and should not be used by application code.
The default value is
Gtk.Overflow.VISIBLE
.
- set_parent(parent)[source]¶
- Parameters:
parent (
Gtk.Widget
) – parent widget
Sets parent as the parent widget of self.
This takes care of details such as updating the state and style of the child to reflect its new location and resizing the parent. The opposite function is [method`Gtk`.Widget.unparent].
This function is useful only when implementing subclasses of
GtkWidget
.
- set_receives_default(receives_default)[source]¶
- Parameters:
receives_default (
bool
) – whether or not self can be a default widget.
Specifies whether self will be treated as the default widget within its toplevel when it has the focus, even if another widget is the default.
- set_sensitive(sensitive)[source]¶
-
Sets the sensitivity of a widget.
A widget is sensitive if the user can interact with it. Insensitive widgets are “grayed out” and the user can’t interact with them. Insensitive widgets are known as “inactive”, “disabled”, or “ghosted” in some other toolkits.
- set_size_request(width, height)[source]¶
- Parameters:
Sets the minimum size of a widget.
That is, the widget’s size request will be at least width by height. You can use this function to force a widget to be larger than it normally would be.
In most cases, [method`Gtk`.Window.set_default_size] is a better choice for toplevel windows than this function; setting the default size will still allow users to shrink the window. Setting the size request will force them to leave the window at least as large as the size request.
Note the inherent danger of setting any fixed size - themes, translations into other languages, different fonts, and user action can all change the appropriate size for a given widget. So, it’s basically impossible to hardcode a size that will always be correct.
The size request of a widget is the smallest size a widget can accept while still functioning well and drawing itself correctly. However in some strange cases a widget may be allocated less than its requested size, and in many cases a widget may be allocated more space than it requested.
If the size request in a given direction is -1 (unset), then the “natural” size request of the widget will be used instead.
The size request set here does not include any margin from the properties [property`Gtk`.Widget:margin-start], [property`Gtk`.Widget:margin-end], [property`Gtk`.Widget:margin-top], and [property`Gtk`.Widget:margin-bottom], but it does include pretty much all other padding or border properties set by any subclass of
GtkWidget
.
- set_state_flags(flags, clear)[source]¶
- Parameters:
flags (
Gtk.StateFlags
) – State flags to turn onclear (
bool
) – Whether to clear state before turning on flags
Turns on flag values in the current widget state.
Typical widget states are insensitive, prelighted, etc.
This function accepts the values
Gtk.StateFlags.DIR_LTR
andGtk.StateFlags.DIR_RTL
but ignores them. If you want to set the widget’s direction, use [method`Gtk`.Widget.set_direction].This function is for use in widget implementations.
- set_tooltip_markup(markup)[source]¶
-
Sets markup as the contents of the tooltip, which is marked up with Pango markup.
This function will take care of setting the [property`Gtk`.Widget:has-tooltip] as a side effect, and of the default handler for the [signal`Gtk`.Widget::query-tooltip] signal.
See also [method`Gtk`.Tooltip.set_markup].
- set_tooltip_text(text)[source]¶
-
Sets text as the contents of the tooltip.
If text contains any markup, it will be escaped.
This function will take care of setting [property`Gtk`.Widget:has-tooltip] as a side effect, and of the default handler for the [signal`Gtk`.Widget::query-tooltip] signal.
See also [method`Gtk`.Tooltip.set_text].
- set_valign(align)[source]¶
- Parameters:
align (
Gtk.Align
) – the vertical alignment
Sets the vertical alignment of self.
- set_vexpand(expand)[source]¶
- Parameters:
expand (
bool
) – whether to expand
Sets whether the widget would like any available extra vertical space.
See [method`Gtk`.Widget.set_hexpand] for more detail.
- set_vexpand_set(set)[source]¶
- Parameters:
set (
bool
) – value for vexpand-set property
Sets whether the vexpand flag will be used.
See [method`Gtk`.Widget.set_hexpand_set] for more detail.
- set_visible(visible)[source]¶
- Parameters:
visible (
bool
) – whether the widget should be shown or not
Sets the visibility state of self.
Note that setting this to
True
doesn’t mean the widget is actually viewable, see [method`Gtk`.Widget.get_visible].
- should_layout()[source]¶
-
Returns whether self should contribute to the measuring and allocation of its parent.
This is
False
for invisible children, but also for children that have their own surface.
- show()[source]¶
Flags a widget to be displayed.
Any widget that isn’t shown will not appear on the screen.
Remember that you have to show the containers containing a widget, in addition to the widget itself, before it will appear onscreen.
When a toplevel container is shown, it is immediately realized and mapped; other shown widgets are realized and mapped when their toplevel container is realized and mapped.
Deprecated since version 4.10: Use [method`Gtk`.Widget.set_visible] instead
- size_allocate(allocation, baseline)[source]¶
- Parameters:
allocation (
Gdk.Rectangle
) – position and size to be allocated to selfbaseline (
int
) – The baseline of the child, or -1
Allocates widget with a transformation that translates the origin to the position in allocation.
This is a simple form of [method`Gtk`.Widget.allocate].
- snapshot_child(child, snapshot)[source]¶
- Parameters:
child (
Gtk.Widget
) – a child of selfsnapshot (
Gtk.Snapshot
) –GtkSnapshot
as passed to the widget. In particular, no calls toGtk.Snapshot.translate
() or other transform calls should have been made.
Snapshot the a child of self.
When a widget receives a call to the snapshot function, it must send synthetic [vfunc`Gtk`.Widget.snapshot] calls to all children. This function provides a convenient way of doing this. A widget, when it receives a call to its [vfunc`Gtk`.Widget.snapshot] function, calls
Gtk.Widget.snapshot_child
() once for each child, passing in the snapshot the widget received.Gtk.Widget.snapshot_child
() takes care of translating the origin of snapshot, and deciding whether the child needs to be snapshot.This function does nothing for children that implement
GtkNative
.
- translate_coordinates(dest_widget, src_x, src_y)[source]¶
- Parameters:
dest_widget (
Gtk.Widget
) – aGtk.Widget
src_x (
int
) – X position relative to selfsrc_y (
int
) – Y position relative to self
- Returns:
None
if either widget was not realized, or there was no common ancestor. Otherwise a(dest_x, dest_y)
tuple containing the X and Y position relative to dest_widget.- Return type:
Translate coordinates relative to self’s allocation to coordinates relative to dest_widget’s allocations.
In order to perform this operation, both widget must share a common ancestor.
Deprecated since version 4.12: Use
Gtk.Widget.compute_point
() instead
- trigger_tooltip_query()[source]¶
Triggers a tooltip query on the display where the toplevel of self is located.
- unmap()[source]¶
Causes a widget to be unmapped if it’s currently mapped.
This function is only for use in widget implementations.
- unparent()[source]¶
Dissociate self from its parent.
This function is only for use in widget implementations, typically in dispose.
- unrealize()[source]¶
Causes a widget to be unrealized (frees all GDK resources associated with the widget).
This function is only useful in widget implementations.
- unset_state_flags(flags)[source]¶
- Parameters:
flags (
Gtk.StateFlags
) – State flags to turn off
Turns off flag values for the current widget state.
See [method`Gtk`.Widget.set_state_flags].
This function is for use in widget implementations.
- do_compute_expand(hexpand_p, vexpand_p) virtual¶
-
Computes whether a container should give this widget extra space when possible.
- do_contains(x, y) virtual¶
- Parameters:
- Returns:
True
if widget contains (x, y).- Return type:
Tests if the point at (x, y) is contained in widget.
The coordinates for (x, y) must be in widget coordinates, so (0, 0) is assumed to be the top left of widget's content area.
- do_css_changed(change) virtual¶
- Parameters:
change (
Gtk.CssStyleChange
) –
Vfunc called when the CSS used by widget was changed. Widgets should then discard their caches that depend on CSS and queue resizes or redraws accordingly. The default implementation will take care of this for all the default CSS properties, so implementations must chain up.
- do_direction_changed(previous_direction) virtual¶
- Parameters:
previous_direction (
Gtk.TextDirection
) –
Signal emitted when the text direction of a widget changes.
- do_focus(direction) virtual¶
- Parameters:
direction (
Gtk.DirectionType
) –- Return type:
Vfunc for
Gtk.Widget.child_focus
()
- do_get_request_mode() virtual¶
- Returns:
The
GtkSizeRequestMode
preferred by widget.- Return type:
Gets whether the widget prefers a height-for-width layout or a width-for-height layout.
Single-child widgets generally propagate the preference of their child, more complex widgets need to request something either in context of their children or in context of their allocation capabilities.
- do_grab_focus() virtual¶
-
Causes widget to have the keyboard focus for the
GtkWindow
it’s inside.If widget is not focusable, or its [vfunc`Gtk`.Widget.grab_focus] implementation cannot transfer the focus to a descendant of widget that is focusable, it will not take focus and
False
will be returned.Calling [method`Gtk`.Widget.grab_focus] on an already focused widget is allowed, should not have an effect, and return
True
.
- do_hide() virtual¶
Reverses the effects of
Gtk.Widget.show
().This is causing the widget to be hidden (invisible to the user).
Deprecated since version 4.10: Use [method`Gtk`.Widget.set_visible] instead
- Parameters:
direction (
Gtk.DirectionType
) – direction of focus movement- Returns:
True
if stopping keyboard navigation is fine,False
if the emitting widget should try to handle the keyboard navigation attempt in its parent container(s).- Return type:
Emits the
::keynav-failed
signal on the widget.This function should be called whenever keyboard navigation within a single widget hits a boundary.
The return value of this function should be interpreted in a way similar to the return value of [method`Gtk`.Widget.child_focus]. When
True
is returned, stay in the widget, the failed keyboard navigation is OK and/or there is nowhere we can/should move the focus to. WhenFalse
is returned, the caller should continue with keyboard navigation outside the widget, e.g. by calling [method`Gtk`.Widget.child_focus] on the widget’s toplevel.The default [signal`Gtk`.Widget::keynav-failed] handler returns
False
forGtk.DirectionType.TAB_FORWARD
andGtk.DirectionType.TAB_BACKWARD
. For the other values ofGtkDirectionType
it returnsTrue
.Whenever the default handler returns
True
, it also calls [method`Gtk`.Widget.error_bell] to notify the user of the failed keyboard navigation.A use case for providing an own implementation of
::keynav-failed
(either by connecting to it or by overriding it) would be a row of [class`Gtk`.Entry] widgets where the user should be able to navigate the entire row with the cursor keys, as e.g. known from user interfaces that require entering license keys.
- do_map() virtual¶
Causes a widget to be mapped if it isn’t already.
This function is only for use in widget implementations.
- do_measure(orientation, for_size) virtual¶
- Parameters:
orientation (
Gtk.Orientation
) – the orientation to measurefor_size (
int
) – Size for the opposite of orientation, i.e. if orientation isGtk.Orientation.HORIZONTAL
, this is the height the widget should be measured with. TheGtk.Orientation.VERTICAL
case is analogous. This way, both height-for-width and width-for-height requests can be implemented. If no size is known, -1 can be passed.
- Returns:
- minimum:
location to store the minimum size
- natural:
location to store the natural size
- minimum_baseline:
location to store the baseline position for the minimum size, or -1 to report no baseline
- natural_baseline:
location to store the baseline position for the natural size, or -1 to report no baseline
- Return type:
(minimum:
int
, natural:int
, minimum_baseline:int
, natural_baseline:int
)
Measures widget in the orientation orientation and for the given for_size.
As an example, if orientation is
Gtk.Orientation.HORIZONTAL
and for_size is 300, this functions will compute the minimum and natural width of widget if it is allocated at a height of 300 pixels.See GtkWidget’s geometry management section for a more details on implementing
GtkWidgetClass.measure()
.
- do_mnemonic_activate(group_cycling) virtual¶
- Parameters:
group_cycling (
bool
) –True
if there are other widgets with the same mnemonic- Returns:
True
if the signal has been handled- Return type:
Emits the
::mnemonic-activate
signal.See [signal`Gtk`.Widget::mnemonic-activate].
- do_move_focus(direction) virtual¶
- Parameters:
direction (
Gtk.DirectionType
) –
Signal emitted when a change of focus is requested
- do_query_tooltip(x, y, keyboard_tooltip, tooltip) virtual¶
- Parameters:
x (
int
) –y (
int
) –keyboard_tooltip (
bool
) –tooltip (
Gtk.Tooltip
) –
- Return type:
Signal emitted when “has-tooltip” is
True
and the hover timeout has expired with the cursor hovering “above” widget; or emitted when widget got focus in keyboard mode.
- do_realize() virtual¶
Creates the GDK resources associated with a widget.
Normally realization happens implicitly; if you show a widget and all its parent containers, then the widget will be realized and mapped automatically.
Realizing a widget requires all the widget’s parent widgets to be realized; calling this function realizes the widget’s parents in addition to widget itself. If a widget is not yet inside a toplevel window when you realize it, bad things will happen.
This function is primarily used in widget implementations, and isn’t very useful otherwise. Many times when you think you might need it, a better approach is to connect to a signal that will be called after the widget is realized automatically, such as [signal`Gtk`.Widget::realize].
- do_root() virtual¶
Called when the widget gets added to a
GtkRoot
widget. Must chain up
- do_set_focus_child(child) virtual¶
- Parameters:
child (
Gtk.Widget
orNone
) – a direct child widget of widget orNone
to unset the focus child of widget
Set child as the current focus child of widget.
This function is only suitable for widget implementations. If you want a certain widget to get the input focus, call [method`Gtk`.Widget.grab_focus] on it.
- do_show() virtual¶
Flags a widget to be displayed.
Any widget that isn’t shown will not appear on the screen.
Remember that you have to show the containers containing a widget, in addition to the widget itself, before it will appear onscreen.
When a toplevel container is shown, it is immediately realized and mapped; other shown widgets are realized and mapped when their toplevel container is realized and mapped.
Deprecated since version 4.10: Use [method`Gtk`.Widget.set_visible] instead
- do_size_allocate(width, height, baseline) virtual¶
-
Called to set the allocation, if the widget does not have a layout manager.
- do_snapshot(snapshot) virtual¶
- Parameters:
snapshot (
Gtk.Snapshot
) –
Vfunc called when a new snapshot of the widget has to be taken.
- do_state_flags_changed(previous_state_flags) virtual¶
- Parameters:
previous_state_flags (
Gtk.StateFlags
) –
Signal emitted when the widget state changes, see
Gtk.Widget.get_state_flags
().
- do_system_setting_changed(settings) virtual¶
- Parameters:
settings (
Gtk.SystemSetting
) –
Emitted when a system setting was changed. Must chain up.
- do_unmap() virtual¶
Causes a widget to be unmapped if it’s currently mapped.
This function is only for use in widget implementations.
- do_unrealize() virtual¶
Causes a widget to be unrealized (frees all GDK resources associated with the widget).
This function is only useful in widget implementations.
- do_unroot() virtual¶
Called when the widget is about to be removed from its
GtkRoot
widget. Must chain up
Signal Details¶
- Gtk.Widget.signals.destroy(widget)¶
- Signal Name:
destroy
- Flags:
- Parameters:
widget (
Gtk.Widget
) – The object which received the signal
Signals that all holders of a reference to the widget should release the reference that they hold.
May result in finalization of the widget if all references are released.
This signal is not suitable for saving widget state.
- Gtk.Widget.signals.direction_changed(widget, previous_direction)¶
- Signal Name:
direction-changed
- Flags:
- Parameters:
widget (
Gtk.Widget
) – The object which received the signalprevious_direction (
Gtk.TextDirection
) – the previous text direction of widget
Emitted when the text direction of a widget changes.
- Gtk.Widget.signals.hide(widget)¶
- Signal Name:
hide
- Flags:
- Parameters:
widget (
Gtk.Widget
) – The object which received the signal
Emitted when widget is hidden.
- Signal Name:
keynav-failed
- Flags:
- Parameters:
widget (
Gtk.Widget
) – The object which received the signaldirection (
Gtk.DirectionType
) – the direction of movement
- Returns:
True
if stopping keyboard navigation is fine,False
if the emitting widget should try to handle the keyboard navigation attempt in its parent widget(s).- Return type:
Emitted if keyboard navigation fails.
See [method`Gtk`.Widget.keynav_failed] for details.
- Gtk.Widget.signals.map(widget)¶
- Signal Name:
map
- Flags:
- Parameters:
widget (
Gtk.Widget
) – The object which received the signal
Emitted when widget is going to be mapped.
A widget is mapped when the widget is visible (which is controlled with [property`Gtk`.Widget:visible]) and all its parents up to the toplevel widget are also visible.
The
::map
signal can be used to determine whether a widget will be drawn, for instance it can resume an animation that was stopped during the emission of [signal`Gtk`.Widget::unmap].
- Gtk.Widget.signals.mnemonic_activate(widget, group_cycling)¶
- Signal Name:
mnemonic-activate
- Flags:
- Parameters:
widget (
Gtk.Widget
) – The object which received the signalgroup_cycling (
bool
) –True
if there are other widgets with the same mnemonic
- Returns:
True
to stop other handlers from being invoked for the event.False
to propagate the event further.- Return type:
Emitted when a widget is activated via a mnemonic.
The default handler for this signal activates widget if group_cycling is
False
, or just makes widget grab focus if group_cycling isTrue
.
- Gtk.Widget.signals.move_focus(widget, direction)¶
- Signal Name:
move-focus
- Flags:
- Parameters:
widget (
Gtk.Widget
) – The object which received the signaldirection (
Gtk.DirectionType
) – the direction of the focus move
Emitted when the focus is moved.
The
::move-focus
signal is a keybinding signal.The default bindings for this signal are <kbd>Tab</kbd> to move forward, and <kbd>Shift</kbd>+<kbd>Tab</kbd> to move backward.
- Gtk.Widget.signals.query_tooltip(widget, x, y, keyboard_mode, tooltip)¶
- Signal Name:
query-tooltip
- Flags:
- Parameters:
widget (
Gtk.Widget
) – The object which received the signalx (
int
) – the x coordinate of the cursor position where the request has been emitted, relative to widget's left sidey (
int
) – the y coordinate of the cursor position where the request has been emitted, relative to widget's topkeyboard_mode (
bool
) –True
if the tooltip was triggered using the keyboardtooltip (
Gtk.Tooltip
) – aGtkTooltip
- Returns:
- Return type:
Emitted when the widget’s tooltip is about to be shown.
This happens when the [property`Gtk`.Widget:has-tooltip] property is
True
and the hover timeout has expired with the cursor hovering “above” widget; or emitted when widget got focus in keyboard mode.Using the given coordinates, the signal handler should determine whether a tooltip should be shown for widget. If this is the case
True
should be returned,False
otherwise. Note that if keyboard_mode isTrue
, the values of x and y are undefined and should not be used.The signal handler is free to manipulate tooltip with the therefore destined function calls.
- Gtk.Widget.signals.realize(widget)¶
- Signal Name:
realize
- Flags:
- Parameters:
widget (
Gtk.Widget
) – The object which received the signal
Emitted when widget is associated with a
GdkSurface
.This means that [method`Gtk`.Widget.realize] has been called or the widget has been mapped (that is, it is going to be drawn).
- Gtk.Widget.signals.show(widget)¶
- Signal Name:
show
- Flags:
- Parameters:
widget (
Gtk.Widget
) – The object which received the signal
Emitted when widget is shown.
- Gtk.Widget.signals.state_flags_changed(widget, flags)¶
- Signal Name:
state-flags-changed
- Flags:
- Parameters:
widget (
Gtk.Widget
) – The object which received the signalflags (
Gtk.StateFlags
) – The previous state flags.
Emitted when the widget state changes.
See [method`Gtk`.Widget.get_state_flags].
- Gtk.Widget.signals.unmap(widget)¶
- Signal Name:
unmap
- Flags:
- Parameters:
widget (
Gtk.Widget
) – The object which received the signal
Emitted when widget is going to be unmapped.
A widget is unmapped when either it or any of its parents up to the toplevel widget have been set as hidden.
As
::unmap
indicates that a widget will not be shown any longer, it can be used to, for example, stop an animation on the widget.
- Gtk.Widget.signals.unrealize(widget)¶
- Signal Name:
unrealize
- Flags:
- Parameters:
widget (
Gtk.Widget
) – The object which received the signal
Emitted when the
GdkSurface
associated with widget is destroyed.This means that [method`Gtk`.Widget.unrealize] has been called or the widget has been unmapped (that is, it is going to be hidden).
Property Details¶
- Gtk.Widget.props.can_focus¶
- Name:
can-focus
- Type:
- Default Value:
- Flags:
Whether the widget or any of its descendents can accept the input focus.
This property is meant to be set by widget implementations, typically in their instance init function.
- Gtk.Widget.props.can_target¶
- Name:
can-target
- Type:
- Default Value:
- Flags:
Whether the widget can receive pointer events.
- Gtk.Widget.props.css_classes¶
-
A list of css classes applied to this widget.
- Gtk.Widget.props.css_name¶
- Name:
css-name
- Type:
- Default Value:
- Flags:
The name of this widget in the CSS tree.
This property is meant to be set by widget implementations, typically in their instance init function.
- Gtk.Widget.props.cursor¶
- Name:
cursor
- Type:
- Default Value:
- Flags:
The cursor used by widget.
- Gtk.Widget.props.focus_on_click¶
- Name:
focus-on-click
- Type:
- Default Value:
- Flags:
Whether the widget should grab focus when it is clicked with the mouse.
This property is only relevant for widgets that can take focus.
- Gtk.Widget.props.focusable¶
- Name:
focusable
- Type:
- Default Value:
- Flags:
Whether this widget itself will accept the input focus.
- Gtk.Widget.props.halign¶
- Name:
halign
- Type:
- Default Value:
- Flags:
How to distribute horizontal space if widget gets extra space.
- Gtk.Widget.props.has_default¶
- Name:
has-default
- Type:
- Default Value:
- Flags:
Whether the widget is the default widget.
- Gtk.Widget.props.has_focus¶
- Name:
has-focus
- Type:
- Default Value:
- Flags:
Whether the widget has the input focus.
- Gtk.Widget.props.has_tooltip¶
- Name:
has-tooltip
- Type:
- Default Value:
- Flags:
Enables or disables the emission of the
::query-tooltip
signal on widget.A value of
True
indicates that widget can have a tooltip, in this case the widget will be queried using [signal`Gtk`.Widget::query-tooltip] to determine whether it will provide a tooltip or not.
- Gtk.Widget.props.height_request¶
- Name:
height-request
- Type:
- Default Value:
-1
- Flags:
Override for height request of the widget.
If this is -1, the natural request will be used.
- Gtk.Widget.props.hexpand¶
- Name:
hexpand
- Type:
- Default Value:
- Flags:
Whether to expand horizontally.
- Gtk.Widget.props.hexpand_set¶
- Name:
hexpand-set
- Type:
- Default Value:
- Flags:
Whether to use the
hexpand
property.
- Gtk.Widget.props.layout_manager¶
- Name:
layout-manager
- Type:
- Default Value:
- Flags:
The
GtkLayoutManager
instance to use to compute the preferred size of the widget, and allocate its children.This property is meant to be set by widget implementations, typically in their instance init function.
- Gtk.Widget.props.margin_bottom¶
- Name:
margin-bottom
- Type:
- Default Value:
0
- Flags:
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 [method`Gtk`.Widget.set_size_request] for example.
- Gtk.Widget.props.margin_end¶
- Name:
margin-end
- Type:
- Default Value:
0
- Flags:
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 [method`Gtk`.Widget.set_size_request] for example.
- Gtk.Widget.props.margin_start¶
- Name:
margin-start
- Type:
- Default Value:
0
- Flags:
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 [method`Gtk`.Widget.set_size_request] for example.
- Gtk.Widget.props.margin_top¶
- Name:
margin-top
- Type:
- Default Value:
0
- Flags:
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 [method`Gtk`.Widget.set_size_request] for example.
- Gtk.Widget.props.name¶
-
The name of the widget.
- Gtk.Widget.props.opacity¶
- Name:
opacity
- Type:
- Default Value:
1.0
- Flags:
The requested opacity of the widget.
- Gtk.Widget.props.overflow¶
- Name:
overflow
- Type:
- Default Value:
- Flags:
How content outside the widget’s content area is treated.
This property is meant to be set by widget implementations, typically in their instance init function.
- Gtk.Widget.props.parent¶
- Name:
parent
- Type:
- Default Value:
- Flags:
The parent widget of this widget.
- Gtk.Widget.props.receives_default¶
- Name:
receives-default
- Type:
- Default Value:
- Flags:
Whether the widget will receive the default action when it is focused.
- Gtk.Widget.props.root¶
- Name:
root
- Type:
- Default Value:
- Flags:
The
GtkRoot
widget of the widget tree containing this widget.This will be
None
if the widget is not contained in a root widget.
- Gtk.Widget.props.scale_factor¶
-
The scale factor of the widget.
- Gtk.Widget.props.sensitive¶
- Name:
sensitive
- Type:
- Default Value:
- Flags:
Whether the widget responds to input.
- Gtk.Widget.props.tooltip_markup¶
- Name:
tooltip-markup
- Type:
- Default Value:
- Flags:
Sets the text of tooltip to be the given string, which is marked up with Pango markup.
Also see [method`Gtk`.Tooltip.set_markup].
This is a convenience property which will take care of getting the tooltip shown if the given string is not
None
: [property`Gtk`.Widget:has-tooltip] will automatically be set toTrue
and there will be taken care of [signal`Gtk`.Widget::query-tooltip] in the default signal handler.Note that if both [property`Gtk`.Widget:tooltip-text] and [property`Gtk`.Widget:tooltip-markup] are set, the last one wins.
- Gtk.Widget.props.tooltip_text¶
- Name:
tooltip-text
- Type:
- Default Value:
- Flags:
Sets the text of tooltip to be the given string.
Also see [method`Gtk`.Tooltip.set_text].
This is a convenience property which will take care of getting the tooltip shown if the given string is not
None
: [property`Gtk`.Widget:has-tooltip] will automatically be set toTrue
and there will be taken care of [signal`Gtk`.Widget::query-tooltip] in the default signal handler.Note that if both [property`Gtk`.Widget:tooltip-text] and [property`Gtk`.Widget:tooltip-markup] are set, the last one wins.
- Gtk.Widget.props.valign¶
- Name:
valign
- Type:
- Default Value:
- Flags:
How to distribute vertical space if widget gets extra space.
- Gtk.Widget.props.vexpand¶
- Name:
vexpand
- Type:
- Default Value:
- Flags:
Whether to expand vertically.
- Gtk.Widget.props.vexpand_set¶
- Name:
vexpand-set
- Type:
- Default Value:
- Flags:
Whether to use the
vexpand
property.
- Gtk.Widget.props.visible¶
- Name:
visible
- Type:
- Default Value:
- Flags:
Whether the widget is visible.
- Gtk.Widget.props.width_request¶
- Name:
width-request
- Type:
- Default Value:
-1
- Flags:
Override for width request of the widget.
If this is -1, the natural request will be used.