gtk2Hs:包含文字和图片的组合框

时间:2015-02-01 00:09:01

标签: haskell combobox gtk2hs

Gtk提供的基本ComboBox只能处理StringPixbuf

但我想在同一行选择附近找到一个文字和一张图片。

我看了一会儿如何使用Haskell和Gtk2Hs获得结果。

enter image description here

1 个答案:

答案 0 :(得分:2)

以下是获取预期结果的代码:

pic1 <- pixbufNewFromFile "Picture_1.png"
pic2 <- pixbufNewFromFile "Picture_2.png"
pic3 <- pixbufNewFromFile "Picture_3.png"

let lstsecrep = [
                  ("Picture 1",pic1)
                , ("Picture 2",pic2)
                , ("Picture 3",pic3)
                ]

lststorerep <- listStoreNew lstsecrep 

customStoreSetColumn lststorerep (makeColumnIdString 0) fst
customStoreSetColumn lststorerep (makeColumnIdPixbuf 1) snd

combo <- comboBoxNewWithModel lststorerep

rendertxt <- cellRendererTextNew
renderpic <- cellRendererPixbufNew

cellLayoutPackStart  combo rendertxt False
cellLayoutPackStart  combo renderpic True
cellLayoutAddColumnAttribute combo rendertxt cellText $ makeColumnIdString 0
cellLayoutAddColumnAttribute combo renderpic cellPixbuf $ makeColumnIdPixbuf 1

最好的问候。