Combobox 工具栏中的组合框
很抱歉出现转储(?)问题。如何将GTK组合框添加到工具栏?我用谷歌搜索了一下,但没有找到答案。它编译时不会出错,但当我运行应用程序时,控制台会显示以下消息:Combobox 工具栏中的组合框,combobox,gtk,toolbar,vala,Combobox,Gtk,Toolbar,Vala,很抱歉出现转储(?)问题。如何将GTK组合框添加到工具栏?我用谷歌搜索了一下,但没有找到答案。它编译时不会出错,但当我运行应用程序时,控制台会显示以下消息: Gtk-CRITICAL **: gtk_toolbar_insert: assertion 'GTK_IS_TOOL_ITEM (item)' failed 以下是工具栏+组合框的示例: using Gtk; public class Example : Object { private Window _win; p
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;
}
使用Gtk;
公共类示例:对象{
私人窗口(u win),;
私人工具栏(tb);
公共示例(){
_win=新窗口();
_win.title=“测试”;
_win.window\u position=WindowPosition.CENTER;
_赢。设置默认大小(800600);
_赢、毁、连(Gtk.main_退出);
_tb=新工具栏();
var img=new Image.from_icon_name(“document new”,Gtk.IconSize.SMALL_工具栏);
var btn=新工具按钮(img,“新”);
_tb.add(btn);
添加_zoombox();
var vbox=新框(方向垂直,0);
vbox.pack_start(_tb,false,true,0);
_win.add(vbox);
}
私有void add_zoombox(){
ListStore list=新的ListStore(1,typeof(int));
for(int i=25;i自己解决了问题。再次阅读文档后,我发现工具栏只能包含ToolButtons、ToggleToolButtons和RadioToolButtons。要向工具栏添加组合框或任何其他项,必须先将其添加到ToolItem。以下是更改的代码:
ToolItem container = new ToolItem();
_tb.add(container);
container.add(cb);
cb.show();