gtk2Hs:组合框的文字和图片(gtk2Hs : Combo box with text and

2019-10-21 17:50发布

基本ComboBox被GTK提供的只能处理一个StringPixbuf

但我想一个文本和在同一行选择附近的照片。

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

Answer 1:

下面是代码,以获得预期的结果:

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

最好的祝福。



文章来源: gtk2Hs : Combo box with text and pictures