抱歉转储(?)问题。如何将 GTK 组合框添加到工具栏?我已经用谷歌搜索了它,但没有找到答案。它编译没有错误,但是当我运行应用程序时,控制台会打印以下消息:
Gtk-CRITICAL **: gtk_toolbar_insert: assertion 'GTK_IS_TOOL_ITEM (item)' failed
以下是工具栏+组合框的示例:
using Gtk;
public class Example : Object {
private Window _win;
private Toolbar _tb;
public Example() {
_win = new Window();
_win.title = "Test";
_win.window_position = WindowPosition.CENTER;
_win.set_default_size(800, 600);
_win.destroy.connect(Gtk.main_quit);
_tb = new Toolbar();
var img = new Image.from_icon_name("document-new", Gtk.IconSize.SMALL_TOOLBAR);
var btn = new ToolButton(img, "New");
_tb.add(btn);
add_zoombox();
var vbox = new Box(Orientation.VERTICAL, 0);
vbox.pack_start(_tb, false, true, 0);
_win.add(vbox);
}
private void add_zoombox() {
ListStore list = new ListStore(1, typeof (int));
for(int i = 25; i<= 400; i*=2) {
TreeIter iter;
list.append(out iter);
list.set(iter, 0, i);
}
ComboBox cb = new ComboBox.with_model(list);
CellRendererText r = new CellRendererText();
cb.pack_start(r, false);
cb.set_active(0);
_tb.add(cb);
cb.show();
}
public void show_window() {
_win.show_all();
}
}
public static int main (string[] args) {
Gtk.init(ref args);
Example ex = new Example();
ex.show_window();
Gtk.main();
return 0;
}