gtk2Hs:带文本和图片的组合框 [英] gtk2Hs : Combo box with text and pictures

查看:145
本文介绍了gtk2Hs:带文本和图片的组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Gtk提供的基本 ComboBox 只能处理 String Pixbuf

The basic ComboBox provided by Gtk can only handle a String or a Pixbuf

但我想要在同一行选择上附加文字和图片。

But I wanted a text and a picture nearby on the same row of selection.

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

I looked for a while how to obtain the result bellow using Haskell and Gtk2Hs.

推荐答案

这里是获取预期结果的代码: p>

Here is the code to obtain the expected result :

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:带文本和图片的组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆