gpt4 book ai didi

工具栏中的组合框

转载 作者:行者123 更新时间:2023-12-04 04:36:49 26 4
gpt4 key购买 nike

抱歉转储(?)问题。如何将 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;
}

最佳答案

我自己解决了这个问题。再次阅读文档后,我发现工具栏只能包含 ToolButtons、ToggleToolButtons 和 RadioToolButtons。要将组合框或任何其他项目添加到工具栏,必须先将其添加到 ToolItem。这是更改的代码:

ToolItem container = new ToolItem();
_tb.add(container);
container.add(cb);
cb.show();

关于工具栏中的组合框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19629552/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com