I don't seem to be able to write working code that creates and populates a TreeView using the gtk 3 bindings of gi-gtk
(specifically version 3.0.32). All examples I could find online are for different (and older) bindings that do not apply to gi-gtk
. The documentation itself is particularly useless in this case.
I have tried replicating a simplified version (one row, one column) of this example, as follows
import qualified GI.Gtk as Gtk
import Data.GI.Base.GType (gtypeString)
import Data.GI.Base.GValue (IsGValue(..))
main :: IO ()
main = do
Gtk.init Nothing
w <- Gtk.windowNew Gtk.WindowTypeToplevel
treeView <- Gtk.treeViewNew
store <- Gtk.listStoreNew [gtypeString]
Gtk.treeViewSetModel treeView (Just store)
iter <- Gtk.listStoreAppend store
str <- toGValue (Just "foo")
Gtk.listStoreSetValue store iter 0 str
Gtk.treeViewColumnNew >>= Gtk.treeViewAppendColumn treeView
Gtk.containerAdd w treeView
#showAll w
Gtk.main
The result is obviously wrong, and looks like a partially drawn treeview, no text shown. I have no idea what I'm doing wrong, so I would appreciate if somebody could show how to fix the code or point me to a working example.