gtk.picture

Module for [Picture] class

Types 3

The [gtk.picture.Picture] widget displays a [gdk.paintable.Paintable].

!An example 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 it, there’s a convenience function to do this:

GtkWidget *widget = gtk_picture_new_for_filename ("myfile.png");

If the file isn’t 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 [gdk.texture.Texture.newFromFile], then create the [gtk.picture.Picture] with [gtk.picture.Picture.newForPaintable].

Sometimes an application will want to avoid depending on external data files, such as image files. See the documentation of [gio.resource.Resource] for details. In this case, [gtk.picture.Picture.newForResource] and [gtk.picture.Picture.setResource] should be used.

[gtk.picture.Picture] displays an image at its natural size. See [gtk.image.Image] if you want to display a fixed-size image, such as an icon.

Sizing the paintable

You can influence how the paintable is displayed inside the [gtk.picture.Picture] by changing property@Gtk.Picture:content-fit. See [gtk.types.ContentFit] for details. property@Gtk.Picture:can-shrink 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. And [gtk.widget.Widget.halign] and [gtk.widget.Widget.valign] can be used to make sure the paintable doesn't fill all available space but is instead displayed at its original size.

CSS nodes

[gtk.picture.Picture] has a single CSS node with the name picture.

Accessibility

[gtk.picture.Picture] uses the [gtk.types.AccessibleRole.Img] role.

Methods
GType _gType() @property
Picture self()Returns `this`, for use in `with` statements.
PictureGidBuilder builder()Get builder for [gtk.picture.Picture] Returns: New builder object
string alternativeText() @propertyGet `alternativeText` property. Returns: The alternative textual description for the picture.
void alternativeText(string propval) @propertySet `alternativeText` property. Params: propval = The alternative textual description for the picture.
bool canShrink() @propertyGet `canShrink` property. Returns: If the [gtk.picture.Picture] can be made smaller than the natural size of its contents.
void canShrink(bool propval) @propertySet `canShrink` property. Params: propval = If the [gtk.picture.Picture] can be made smaller than the natural size of its contents.
gtk.types.ContentFit contentFit() @propertyGet `contentFit` property. Returns: How the content should be resized to fit inside the [gtk.picture.Picture].
void contentFit(gtk.types.ContentFit propval) @propertySet `contentFit` property. Params: propval = How the content should be resized to fit inside the [gtk.picture.Picture].
gio.file.File file() @propertyGet `file` property. Returns: The [gio.file.File] that is displayed or null if none.
void file(gio.file.File propval) @propertySet `file` property. Params: propval = The [gio.file.File] that is displayed or null if none.
bool keepAspectRatio() @propertyGet `keepAspectRatio` property. Returns: Whether the GtkPicture will render its contents trying to preserve the aspect ratio.
void keepAspectRatio(bool propval) @propertySet `keepAspectRatio` property. Params: propval = Whether the GtkPicture will render its contents trying to preserve the aspect ratio.
gdk.paintable.Paintable paintable() @propertyGet `paintable` property. Returns: The [gdk.paintable.Paintable] to be displayed by this [gtk.picture.Picture].
void paintable(gdk.paintable.Paintable propval) @propertySet `paintable` property. Params: propval = The [gdk.paintable.Paintable] to be displayed by this [gtk.picture.Picture].
gtk.picture.Picture newForFile(gio.file.File file = null)Creates a new [gtk.picture.Picture] displaying the given file.
gtk.picture.Picture newForFilename(string filename = null)Creates a new [gtk.picture.Picture] displaying the file filename.
gtk.picture.Picture newForPaintable(gdk.paintable.Paintable paintable = null)Creates a new [gtk.picture.Picture] displaying paintable.
gtk.picture.Picture newForPixbuf(gdkpixbuf.pixbuf.Pixbuf pixbuf = null)Creates a new [gtk.picture.Picture] displaying pixbuf.
gtk.picture.Picture newForResource(string resourcePath = null)Creates a new [gtk.picture.Picture] displaying the resource at resource_path.
string getAlternativeText()Gets the alternative textual description of the picture.
bool getCanShrink()Returns whether the [gtk.picture.Picture] respects its contents size. Returns: true if the picture can be made smaller than its contents
gtk.types.ContentFit getContentFit()Returns the fit mode for the content of the [gtk.picture.Picture].
gio.file.File getFile()Gets the [gio.file.File] currently displayed if self is displaying a file.
bool getKeepAspectRatio()Returns whether the [gtk.picture.Picture] preserves its contents aspect ratio. Returns: true if the self tries to keep the contents' aspect ratio
gdk.paintable.Paintable getPaintable()Gets the [gdk.paintable.Paintable] being displayed by the [gtk.picture.Picture]. Returns: the displayed paintable
void setAlternativeText(string alternativeText = null)Sets an alternative textual description for the picture contents.
void setCanShrink(bool canShrink)If set to true, the self can be made smaller than its contents.
void setContentFit(gtk.types.ContentFit contentFit)Sets how the content should be resized to fit the [gtk.picture.Picture].
void setFile(gio.file.File file = null)Makes self load and display file.
void setFilename(string filename = null)Makes self load and display the given filename.
void setKeepAspectRatio(bool keepAspectRatio)If set to true, the self will render its contents according to their aspect ratio.
void setPaintable(gdk.paintable.Paintable paintable = null)Makes self display the given paintable.
void setPixbuf(gdkpixbuf.pixbuf.Pixbuf pixbuf = null)Sets a [gtk.picture.Picture] to show a [gdkpixbuf.pixbuf.Pixbuf].
void setResource(string resourcePath = null)Makes self load and display the resource at the given resource_path.
Constructors
this(void * ptr, Flag!"Take" take)
this()Creates a new empty [gtk.picture.Picture] widget. Returns: a newly created [gtk.picture.Picture] widget.
Methods
T alternativeText(string propval)Set `alternativeText` property. Params: propval = The alternative textual description for the picture. Returns: Builder instance for fluent chaining
T canShrink(bool propval)Set `canShrink` property. Params: propval = If the [gtk.picture.Picture] can be made smaller than the natural size of its contents. Returns: Builder instance for fluent chaining
T contentFit(gtk.types.ContentFit propval)Set `contentFit` property. Params: propval = How the content should be resized to fit inside the [gtk.picture.Picture]. Returns: Builder instance for fluent chaining
T file(gio.file.File propval)Set `file` property. Params: propval = The [gio.file.File] that is displayed or null if none. Returns: Builder instance for fluent chaining
T keepAspectRatio(bool propval)Set `keepAspectRatio` property. Params: propval = Whether the GtkPicture will render its contents trying to preserve the aspect ratio. Returns: Builder instance for fluent chaining
T paintable(gdk.paintable.Paintable propval)Set `paintable` property. Params: propval = The [gdk.paintable.Paintable] to be displayed by this [gtk.picture.Picture]. Returns: Builder instance for fluent chaining

Fluent builder for [gtk.picture.Picture]

Methods