简体   繁体   English

如何在Gtk中创建带有图像的组合框?

[英]How to create combobox with images in Gtk?

Can anyone please tell me how to create a combobox like following with Gtk (on Linux)? 任何人都可以告诉我如何创建一个像Gtk一样的组合框(在Linux上)? (I already ask this question for win32 API). (我已经为win32 API提出了这个问题)。

替代文字

A code example or tutorial will be very helpful. 代码示例或教程将非常有用。 I have tried searching this over the internet, but unfortunately documentations/tutorials aren't that much rich for Gtk. 我试过通过互联网搜索这个,但不幸的是,Gtk的文档/教程并不是那么丰富。 Thank you very much. 非常感谢你。

Regards, 问候,

I know how to do this in C, but I'll try to wing it in C++. 我知道如何在C中做到这一点,但我会试着用C ++来实现它。 First of all, use a ComboBox to display your menu, which you will fill using a TreeModel . 首先,使用ComboBox显示您将使用TreeModel填充的菜单。

Create a TreeModelColumnRecord following the example here ; 按照此处的示例创建TreeModelColumnRecord ; you will need just one Gdk::Pixbuf column to display your line images. 你只需要一个Gdk::Pixbuf列来显示你的线条图像。

Pass the TreeModelColumnRecord to the constructor of ListStore . TreeModelColumnRecord传递给ListStore的构造ListStore Fill your ListStore with Gdk::Pixbuf images of your line patterns, and pass that to the constructor of your ComboBox ( ListStore inherits from TreeModel ). 使用行模式的Gdk::Pixbuf图像填充ListStore ,并将其传递给ComboBox的构造函数( ListStore继承自TreeModel )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM