0

Haskellを介して複数の列を持つListStoreモデルを使用してTreeViewでデータをレンダリングするようにGTKに強制することはできません。私は次のコードを持っています

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

しかし、すべての場合で、列ヘッダーと1つの空白行が挿入されたテーブルが表示されます。どんな助けでもありがたいです。

4

1 に答える 1

4

私は重要なことを見逃してしまいました。ListStoreモデルは多態性であるため、モデルに与えられたオブジェクトからモデルがデータを抽出する方法を説明する必要があります。新しい列を追加するたびに、次のようなコードを記述する必要があります(テキストレンダラーの例)。

cellLayoutSetAttributes yourColumn yourRenderer model (\row -> [ cellText := yourPowerfulValueExtractionFunction row ])

あなたのデータはどこにrowありますか。

したがって、これは「バリアント1」で実装されたデータを使用したソリューションのコードです(質問を参照)。

prepareTreeView view = 
    do
    model <- listStoreNew ([] :: [TRow])

    addTextColumn view model one "one"
    addTextColumn view model two "two"

    listStoreAppend model $ TRow { one = "foo", two = "boo" }

    treeViewSetModel view model

-- 
addTextColumn view model f name =
    do
    col <- treeViewColumnNew
    rend <- cellRendererTextNew
    treeViewColumnSetTitle col name
    treeViewColumnPackStart col rend True
    -- LOOK HERE:
    cellLayoutSetAttributes col rend model (\row -> [ cellText := f row ])

    treeViewColumnSetExpand col True
    treeViewAppendColumn view col
于 2011-03-20T06:36:38.473 に答える