In case it might help others, I have copied below the Gtk.jl
code used to produce the following scrollable Tree View
:
Scrollable Gtk Tree View code
using Gtk, Printf
ts = GtkTreeStore(String, String, String, String)
tv = GtkTreeView(GtkTreeModel(ts))
sw = GtkScrolledWindow(tv)
# specific renderers for each of the columns:
rTxt = GtkCellRendererText()
c0 = GtkTreeViewColumn("#", rTxt, Dict([("text", 0)]))
c1 = GtkTreeViewColumn("Name", rTxt, Dict([("text", 1)]))
c2 = GtkTreeViewColumn("Weight", rTxt, Dict([("text", 2)]))
c3 = GtkTreeViewColumn("Units", rTxt, Dict([("text", 3)]))
push!(tv, c0, c1, c2, c3)
# Make columns resizable:
for c in [c0, c1, c2, c3]
GAccessor.resizable(c, true)
end
# Make columns sortable:
for (i,c) in enumerate([c0,c1,c2,c3])
GAccessor.sort_column_id(c, i-1)
end
# Add data to treeview:
iter1 = push!(ts, ("", "FRUITS", "", ""))
push!(ts, ("1", "Oranges", 1000, "kg"), iter1)
push!(ts, ("2", "Apples", 500, "lb"), iter1)
push!(ts, ("3", "Kiwis", 300, "kg"), iter1)
iter2 = push!(ts, ("","VEGETABLES","",""))
push!(ts, ("1", "Lettuce", 20, "lb"), iter2)
push!(ts, ("2", "Avocado", 150, "kg"), iter2)
iter3 = push!(ts, ("","CEREALS","",""))
for i in 1:100
push!(ts, (@sprintf("%3i",i), rand(("Wheat","Rice","Oat")), rand(0:100), "ton"), iter3)
end
# Display
win = GtkWindow(sw, "Tree View")
Gtk.showall(win)
Q: How to set background colors to distinguish different rows?