How can I access a ListStore GtkBuilder

荒凉一梦 提交于 2019-12-13 00:23:38

问题


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....

  1. You can always use castToTreeModel to iterate through the items in the listStore.... This gives read only info though.

  2. 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).

  3. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!