4
A
回答
6
首先你需要一個模型來存儲項目(文本和圖像)。
enum {COL_TEXT, COL_ICON, NUM_COLS};
GtkListStore *store = gtk_list_store_new(2, G_TYPE_STRING, GDK_TYPE_PIXBUF);
/* add some data */
GtkTreeIter iter;
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter, COL_TEXT, some_text, COL_ICON, some_pixbuf, -1);
接下來創建GtkComboBox
(或GtkComboBoxEntry
,您可以跳過創建文本的單元格渲染)。
// GtkComboBoxEntry *combo = gtk_combo_box_entry_new_with_model(GTK_TREE_MODEL(store), COL_TEXT);
GtkComboBox *combo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store));
GtkCellRenderer *renderer;
/* text cell */
renderer = gtk_cell_renderer_text_new();
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), renderer, TRUE);
gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), renderer, "text", COL_TEXT, NULL);
/* icon cell */
renderer = gtk_cell_renderer_pixbuf_new();
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), renderer, FALSE);
gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), renderer, "pixbuf", COL_ICON, NULL);
相關問題
- 1. WPF與圖像組合框
- 2. 如何用Gtk中的圖像創建組合框?
- 3. 如何用Python中的圖像創建GTK組合框?
- 4. 設置組合框的條目(gtk)
- 5. Python的GTK將信號組合框
- 6. Gtk(mm)組合框的極限寬度
- 7. 自定義組合框與繪製圖像到datagrid視圖
- 8. 與組合框
- 9. 與組合框
- 10. iphone,如何像這樣的圖像中創建組合框(生日組合框)
- 11. 組合框項目中的pyqt圖像
- 12. WPF與組合框
- 13. dataGridView與組合框
- 14. 組合框與MySQL
- 15. 組合框與複選框
- 16. 在GTK中組合指針
- 17. Telerik的組合框與圖片
- 18. GTK +顯示圖標圖像
- 19. Imagick組合圖像
- 20. C#WPF組合框與文本框作爲作爲組合框
- 21. 如何在opencv中將RGB圖像與灰色圖像組合?
- 22. WPF組合框不顯示建議像WinForm的組合框
- 23. 組合框不是作爲組合框填充,但像文本
- 24. 多列組合框就像在winforms中的組合框
- 25. gtk中的圖像內存+
- 26. 在GTK中縮放圖像
- 27. 如何添加圖像/圖標與組合框中的每個項目?
- 28. 劍道,組合框與angularjs
- 29. BindingSource與DataGridView組合框
- 30. 問題與組合框
的可能重複[如何創建GTK中的圖像組合框?](http://stackoverflow.com/questions/3441561/how-to-create-combobox-with-images-in-gtk) – ergosys 2012-01-19 22:05:13
對於Python和GObject內省,請參見[此問題](http://stackoverflow.com/q/15807611/247696) – Flimm 2013-04-04 09:37:40