Gtk.CellRendererText


Gtk.CellRendererText — Renders text in a cell

Object Hierarchy:

    GObject
    ╰── GInitiallyUnowned
        ╰── Gtk.CellRenderer
            ╰── Gtk.CellRendererText
                ├── Gtk.CellRendererAccel
                ├── Gtk.CellRendererCombo
                ╰── Gtk.CellRendererSpin

Functions:


Signals:

  • “edited” (renderer, path, new_text, user_data)

Description:

A Gtk.CellRendererText renders a given text in its cell, using the font, color and style information provided by its properties. The text will be ellipsized if it is too long and the Gtk.CellRendererText::ellipsize property allows it.

If the Gtk.CellRenderer::mode is Gtk.CellRendererMode.EDITABLE, the Gtk.CellRendererText allows to edit its text using an entry.


Function Details:

new()

new () -> Gtk.CellRenderer

Creates a new Gtk.CellRendererText. Adjust how text is drawn usingobject properties. Object properties can beset globally (with g_object_set()). Also, with Gtk.TreeViewColumn,you can bind a property to a value in a Gtk.TreeModel. For example,you can bind the “text” property on the cell renderer to a stringvalue in the model, thus rendering a different string in each rowof the Gtk.TreeView

  • Returns: the new cell renderer

set_fixed_height_from_font()

set_fixed_height_from_font (self, number_of_rows:int)

Sets the height of a renderer to explicitly be determined by the “font” and“y_pad” property set on it. Further changes in these properties do notaffect the height, so they must be accompanied by a subsequent call to thisfunction. Using this function is unflexible, and should really only be usedif calculating the size of a cell is too slow (ie, a massive number of cellsdisplayed). If number_of_rows is -1, then the fixed height is unset, andthe height is determined by the properties again.


Example:

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

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

        self.liststore = Gtk.ListStore(str, str)
        self.liststore.append(["Fedora", "http://fedoraproject.org/"])
        self.liststore.append(["Ubuntu", "http://www.ubuntu.com/"])
        self.liststore.append(["Slackware", "http://www.slackware.com/"])

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

        cellrenderertext = Gtk.CellRendererText()

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

        cellrenderertext = Gtk.CellRendererText()
        cellrenderertext.set_property("editable", True)
        cellrenderertext.connect("edited", self.on_cell_edited)

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

    def on_cell_edited(self, cellrenderertext, treepath, text):
        self.liststore[treepath][1] = text

window = CellRendererText()
window.show_all()

Gtk.main()

results matching ""

    No results matching ""