Sign up

How to draw icons in treeview columns

I would like to display icons in the first column of the treeview.

import gtk.Main;
import gtk.MainWindow;
import gtk.Box;
import gtk.TreeView;
import gtk.ListStore;
import gtk.CellRendererPixbuf;
import gtk.TreeViewColumn;
import gtk.CellRendererText;
import gdk.Pixbuf;
import gobject.Value;



class MyWindow: MainWindow
{

    this()
    {
        super("Drawing icons in rows");
        setSizeRequest(500, 200);

        auto tree = new TreeView();
        auto dataModel = new ListStore([GType.STRING, GType.STRING, GType.STRING]);

        auto iconColumn = new TreeViewColumn("Icon", new CellRendererPixbuf(), "pixbuf", 0);
        tree.appendColumn(iconColumn);
        auto nameColumn = new TreeViewColumn("Name", new CellRendererText(), "text", 1);
        tree.appendColumn(nameColumn);
        auto descriptionColumn = new TreeViewColumn("Description", new CellRendererText(), "text", 2);
        tree.appendColumn(descriptionColumn);

        auto iter = dataModel.createIter();
        dataModel.setValue(iter, 0, new Value(new Pixbuf("icon.png")));
        tree.setModel(dataModel);
        add(tree);

        showAll();
    }
}

void main(string[] args)
{
    Main.init(args);
    auto myWindow = new MyWindow();
    Main.run();
}

But the program gives some warning messages:

GLib-GObject-WARNING **: unable to set property pixbuf' of type GdkPixbuf' from value of type `gchararray'

Also I shouldn't figured out what kind of data type to ListStore's constructor. So I simly passed a GType.STRING.

Re: How to draw icons in treeview columns

On 01/30/2017 10:55 AM, Erdem wrote:

I would like to display icons in the first column of the treeview.

...

But the program gives some warning messages:

GLib-GObject-WARNING **: unable to set property pixbuf' of type GdkPixbuf' from value of type `gchararray'

Also I shouldn't figured out what kind of data type to ListStore's constructor. So I simly passed a GType.STRING.

Set the first column type as a pixbuf column:

auto dataModel = new ListStore([Pixbuf.getType(), GType.STRING, 
GType.STRING]);

Re: How to draw icons in treeview columns

On Mon, 30 Jan 2017 19:51:55 +0100, Mike Wey wrote:

Set the first column type as a pixbuf column:

 auto dataModel = new ListStore([Pixbuf.getType(), GType.STRING, 
 GType.STRING]);

Thanks.