Image#
Superclasses: Widget, InitiallyUnowned, Object
Implemented Interfaces: Accessible, Buildable, ConstraintTarget
The GtkImage widget displays an image.
Various kinds of object can be displayed as an image; most typically,
you would load a GdkTexture from a file, using the convenience function
new_from_file, for instance:
GtkWidget *image = gtk_image_new_from_file ("myfile.png");
If the file isn’t loaded successfully, the image 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
new_from_file, then create the GtkImage with
new_from_paintable.
Sometimes an application will want to avoid depending on external data
files, such as image files. See the documentation of GResource inside
GIO, for details. In this case, resource,
new_from_resource, and set_from_resource
should be used.
GtkImage displays its image as an icon, with a size that is determined
by the application. See Picture if you want to show an image
at is actual size.
CSS nodes#
GtkImage has a single CSS node with the name image. The style classes
.normal-icons or .large-icons may appear, depending on the
icon_size property.
Accessibility#
GtkImage uses the GTK_ACCESSIBLE_ROLE_IMG role.
Constructors#
- class Image
-
- classmethod new_from_file(filename: str) Widget#
Creates a new
GtkImagedisplaying the filefilename.If the file isn’t found or can’t be loaded, the resulting
GtkImagewill display a “broken image” icon. This function never returnsNone, it always returns a validGtkImagewidget.If you need to detect failures to load the file, use
new_from_fileto load the file yourself, then create theGtkImagefrom the texture.The storage type (see
get_storage_type) of the returned image is not defined, it will be whatever is appropriate for displaying the file.- Parameters:
filename – a filename
- classmethod new_from_gicon(icon: Icon) Widget#
Creates a
GtkImagedisplaying an icon from the current icon theme.If the icon name isn’t known, a “broken image” icon will be displayed instead. If the current icon theme is changed, the icon will be updated appropriately.
- Parameters:
icon – an icon
- classmethod new_from_icon_name(icon_name: str | None = None) Widget#
Creates a
GtkImagedisplaying an icon from the current icon theme.If the icon name isn’t known, a “broken image” icon will be displayed instead. If the current icon theme is changed, the icon will be updated appropriately.
- Parameters:
icon_name – an icon name
- classmethod new_from_paintable(paintable: Paintable | None = None) Widget#
Creates a new
GtkImagedisplayingpaintable.The
GtkImagedoes not assume a reference to the paintable; you still need to unref it if you own references.GtkImagewill add its own reference rather than adopting yours.The
GtkImagewill track changes to thepaintableand update its size and contents in response to it.- Parameters:
paintable – a
GdkPaintable
- classmethod new_from_pixbuf(pixbuf: Pixbuf | None = None) Widget#
Creates a new
GtkImagedisplayingpixbuf.The
GtkImagedoes not assume a reference to the pixbuf; you still need to unref it if you own references.GtkImagewill add its own reference rather than adopting yours.This is a helper for
new_from_paintable, and you can’t get back the exact pixbuf once this is called, only a texture.Note that this function just creates an
GtkImagefrom the pixbuf. TheGtkImagecreated will not react to state changes. Should you want that, you should usenew_from_icon_name.Deprecated since version 4.12:
- Use
new_from_paintableand new_for_pixbufinstead
- Parameters:
pixbuf – a
GdkPixbuf
- Use
- classmethod new_from_resource(resource_path: str) Widget#
Creates a new
GtkImagedisplaying the resource fileresource_path.If the file isn’t found or can’t be loaded, the resulting
GtkImagewill display a “broken image” icon. This function never returnsNone, it always returns a validGtkImagewidget.If you need to detect failures to load the file, use
new_from_fileto load the file yourself, then create theGtkImagefrom the pixbuf.The storage type (see
get_storage_type) of the returned image is not defined, it will be whatever is appropriate for displaying the file.- Parameters:
resource_path – a resource path
Methods#
- class Image
-
- get_gicon() Icon | None#
Gets the
GIconbeing displayed by theGtkImage.The storage type of the image must be
EMPTYorGICON(seeget_storage_type). The caller of this function does not own a reference to the returnedGIcon.
- get_icon_name() str | None#
Gets the icon name and size being displayed by the
GtkImage.The storage type of the image must be
EMPTYorICON_NAME(seeget_storage_type). The returned string is owned by theGtkImageand should not be freed.
- get_paintable() Paintable | None#
Gets the image
GdkPaintablebeing displayed by theGtkImage.The storage type of the image must be
EMPTYorPAINTABLE(seeget_storage_type). The caller of this function does not own a reference to the returned paintable.
- get_storage_type() ImageType#
Gets the type of representation being used by the
GtkImageto store image data.If the
GtkImagehas no image data, the return value will beEMPTY.
- set_from_file(filename: str | None = None) None#
Sets a
GtkImageto show a file.See
new_from_filefor details.- Parameters:
filename – a filename
- set_from_gicon(icon: Icon) None#
Sets a
GtkImageto show aGIcon.See
new_from_giconfor details.- Parameters:
icon – an icon
- set_from_icon_name(icon_name: str | None = None) None#
Sets a
GtkImageto show a named icon.See
new_from_icon_namefor details.- Parameters:
icon_name – an icon name
- set_from_paintable(paintable: Paintable | None = None) None#
Sets a
GtkImageto show aGdkPaintable.See
new_from_paintablefor details.- Parameters:
paintable – a
GdkPaintable
- set_from_pixbuf(pixbuf: Pixbuf | None = None) None#
Sets a
GtkImageto show aGdkPixbuf.See
new_from_pixbuffor details.Note: This is a helper for
set_from_paintable, and you can’t get back the exact pixbuf once this is called, only a paintable.Deprecated since version 4.12: Use
set_from_paintableinstead- Parameters:
pixbuf – a
GdkPixbuforNULL
- set_from_resource(resource_path: str | None = None) None#
Sets a
GtkImageto show a resource.See
new_from_resourcefor details.- Parameters:
resource_path – a resource path
- set_icon_size(icon_size: IconSize) None#
Suggests an icon size to the theme for named icons.
- Parameters:
icon_size – the new icon size
- set_pixel_size(pixel_size: int) None#
Sets the pixel size to use for named icons.
If the pixel size is set to a value != -1, it is used instead of the icon size set by
set_from_icon_name.- Parameters:
pixel_size – the new pixel size
Properties#
- class Image