问题
I'm using the following code to load my gui's elements:
import Graphics.UI.Gtk
main = do
initGUI
-- loading
builder <- builderNew
builderAddFromFile builder "gui.glade"
window <- builderGetObject builder castToWindow "window"
onDestroy window mainQuit
widgetShowAll window
mainGUI
How could I access a ListStore
named "listStore", like how I've accessed a Window
named "window"
Example:
-- doesn't compile because castToListStore is part of a hidden module, unlike castToWindow :(
listStore <- builderGetObject builder castToListStore "listStore"
回答1:
It depends what you want to do with it....
You can always use castToTreeModel to iterate through the items in the listStore.... This gives read only info though.
You can just ignore the data in the listStore altogether in Haskell, and just wire it up to be used by the appropriate widget in the glade file. This makes sense for a fixed listStore (ie- table of contents or something that doesn't make sense to change or query).
You can create the listStore in haskell directly and bind it to the widget that uses it using treeViewSetModel. This gives you full access to the data, you can add or delete items and it will change in the view.
来源:https://stackoverflow.com/questions/20183600/how-can-i-access-a-liststore-gtkbuilder