Gtk.CellRendererPixbuf


Gtk.CellRendererPixbuf — Renders a pixbuf in a cell

Object Hierarchy:

    GObject
    ╰── GInitiallyUnowned
        ╰── Gtk.CellRenderer
            ╰── Gtk.CellRendererPixbuf

Functions:

  • new () -> Gtk.CellRenderer

Description:

A Gtk.CellRendererPixbuf can be used to render an image in a cell. It allows to render either a given Gdk.Pixbuf (set via the Gtk.CellRendererPixbuf::pixbuf property) or a named icon (set via the Gtk.CellRendererPixbuf::icon-name property).

To support the tree view, Gtk.CellRendererPixbuf also supports rendering two alternative pixbufs, when the Gtk.CellRenderer::is-expander property is True.

If the Gtk.CellRenderer::is-expanded property is True and the Gtk.CellRendererPixbuf::pixbuf-expander-open property is set to a pixbuf, it renders that pixbuf.

If the Gtk.CellRenderer::is-expanded property is False and the Gtk.CellRendererPixbuf::pixbuf-expander-closed property is set to a pixbuf, it renders that one.


Function Details:

new()

new () -> Gtk.CellRenderer

Creates a new Gtk.CellRendererPixbuf. Adjust renderingparameters using object properties. Object properties can be setglobally (with g_object_set()). Also, with `Gtk.TreeViewColumn, youcan bind a property to a value in aGtk.TreeModel. For example, youcan bind the “pixbuf” property on the cell renderer to a pixbuf valuein the model, thus rendering a different image in each row of theGtk.TreeView`.

  • Returns: the new cell renderer

Example:

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from gi.repository import GdkPixbuf

class CellRendererPixbuf(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self)
        self.set_title("CellRendererPixbuf")
        self.connect("destroy", Gtk.main_quit)

        liststore = Gtk.ListStore(str, GdkPixbuf.Pixbuf)

        icon = GdkPixbuf.Pixbuf.new_from_file_at_size("../_resources/fedora.ico", 16, 16)
        liststore.append(["Fedora", icon])
        icon = GdkPixbuf.Pixbuf.new_from_file_at_size("../_resources/opensuse.ico", 16, 16)
        liststore.append(["OpenSuSE", icon])
        icon = GdkPixbuf.Pixbuf.new_from_file_at_size("../_resources/gentoo.ico", 16, 16)
        liststore.append(["Gentoo", icon])

        treeview = Gtk.TreeView()
        treeview.set_model(liststore)
        self.add(treeview)

        cellrenderertext = Gtk.CellRendererText()

        treeviewcolumn = Gtk.TreeViewColumn("Distribution")
        treeview.append_column(treeviewcolumn)
        treeviewcolumn.pack_start(cellrenderertext, True)
        treeviewcolumn.add_attribute(cellrenderertext, "text", 0)

        cellrendererpixbuf = Gtk.CellRendererPixbuf()

        treeviewcolumn = Gtk.TreeViewColumn("Logo")
        treeview.append_column(treeviewcolumn)
        treeviewcolumn.pack_start(cellrendererpixbuf, False)
        treeviewcolumn.add_attribute(cellrendererpixbuf, "pixbuf", 1)

window = CellRendererPixbuf()
window.show_all()

Gtk.main()

results matching ""

    No results matching ""