Package: gtk

Class gtk:picture

Superclasses

Documented Subclasses

None

Direct Slots

alternative-text
The alternative-text property of type :string (Read / Write)
The alternative textual description for the picture.
Default value: nil
can-shrink
The can-shrink property of type :boolean (Read / Write)
Whether the picture can be made smaller than the natural size of its contents.
Default value: true
content-fit
The content-fit property of type gtk:content-fit (Read / Write)
How the content should be resized to fit inside the picture. Since 4.8
Default value: :contain
file
The file property of type g:file (Read / Write)
The file that is displayed or nil if none.
Default value: nil
keep-aspect-ratio
The keep-aspect-ratio property of type :boolean (Read / Write)
Whether the picture will render its contents trying to preserve the aspect ratio of the contents. Deprecated since 4.8, use the content-fit property instead.
Default value: true
paintable
The paintable property of type gdk:paintable (Read / Write)
The paintable to be displayed by the picture.
Default value: nil

Details

The gtk:picture widget displays a gdk:paintable object.

Figure: GtkPicture

Many convenience functions are provided to make pictures simple to use. For example, if you want to load an image from a file, and then display that, there is a convenience function to do this:
(let ((picture (gtk:picture-new-for-filename "myfile.png")))
   ... )  
If the file is not loaded successfully, the picture will contain a "broken image" icon similar to that used in many web browsers. If you want to handle errors in loading the file yourself, for example by displaying an error message, then load the image with the gdk:texture-new-from-file function, then create the gtk:picture widget with the gtk:picture-new-for-paintable function.

Sometimes an application will want to avoid depending on external data files, such as image files. See the documentation of the g:resource API for details. In this case, the gtk:picture-new-for-resource and gtk:picture-set-resource functions should be used.

Sizing the paintable
You can influence how the paintable is displayed inside the gtk:picture widget by changing the content-fit property. See the gtk:content-fit enumeration for details. The can-shrink property can be unset to make sure that paintables are never made smaller than their ideal size - but be careful if you do not know the size of the paintable in use, like when displaying user-loaded images. This can easily cause the picture to grow larger than the screen. The halign and valign properties can be used to make sure the paintable does not fill all available space but is instead displayed at its original size.

CSS nodes

The gtk:picture implementation has a single CSS node with the name picture.

Accessibility

The gtk:picture implementation uses the :img role of the gtk:accessible-role enumeration.
 

Returned by

Slot Access Functions

Inherited Slot Access Functions

See also

2024-10-13