Gtk2hs 多列 TreeView 与 ListStore 问题
我无法通过 Haskell 强制 GTK 使用具有多列的 ListStore 模型在 TreeView 中呈现数据。我有以下代码
addTextColumn view name =
do
col <- treeViewColumnNew
rend <- cellRendererTextNew
treeViewColumnSetTitle col name
treeViewColumnPackStart col rend True
treeViewColumnSetExpand col True
treeViewAppendColumn view col
prepareTreeView view =
do
addTextColumn view "column1"
addTextColumn view "column2"
--adding data here
然后我尝试添加一些数据,但出现问题。我尝试了这些:
--variant 1 (data TRow = TRow {one::String, two::String}
model <- listStoreNew ([] :: [TRow])
listStoreAppend model $ TRow { one = "Foo", two = "Boo" }
treeViewSetModel view model
--variant 2
model <- listStoreNew ([] :: [[String]])
listStoreAppend model ["foo","boo"]
treeViewSetModel view model
--variant 3
model <- listStoreNew ([] :: [(String, String)])
listStoreAppend model ("foo", "boo")
treeViewSetModel view model
但在所有情况下,我都会看到带有列标题和插入一个空白行的表格。任何帮助将不胜感激。
I cannot force GTK to render data in TreeView with ListStore model with multiple columns through Haskell. I have the following code
addTextColumn view name =
do
col <- treeViewColumnNew
rend <- cellRendererTextNew
treeViewColumnSetTitle col name
treeViewColumnPackStart col rend True
treeViewColumnSetExpand col True
treeViewAppendColumn view col
prepareTreeView view =
do
addTextColumn view "column1"
addTextColumn view "column2"
--adding data here
Then I try to add some data, and there are problems. I tried these:
--variant 1 (data TRow = TRow {one::String, two::String}
model <- listStoreNew ([] :: [TRow])
listStoreAppend model $ TRow { one = "Foo", two = "Boo" }
treeViewSetModel view model
--variant 2
model <- listStoreNew ([] :: [[String]])
listStoreAppend model ["foo","boo"]
treeViewSetModel view model
--variant 3
model <- listStoreNew ([] :: [(String, String)])
listStoreAppend model ("foo", "boo")
treeViewSetModel view model
But in all cases I see the table with column header and one blank row inserted. Any help will be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我错过了一件重要的事情。
由于 ListStore 模型是多态的,因此您必须描述模型应如何从给定的对象中提取数据。每次添加新列时,您都应该编写如下代码(文本渲染器示例):
其中
row
是您的数据。这是使用“变体 1”实现的数据的解决方案的代码(参见问题):
I have been missed an important thing.
Since the ListStore model is polymorphic you must describe HOW the model should extract data from objects given to it. Every time you add the new column you should write the code like this (text renderer example):
where
row
is your data.So this is the code of the solution with data implemented with "variant 1" (see question):