我遗漏了一些与 Glade gtkbuilder 和连接信号有关的明显内容。帮助?
我用空地制作界面。效果很好。 我编写了一个很小的主函数,它调用 gtkbuilder 并渲染空地文件中的所有内容。
Gtk::Main kit(num, opts);
// Load the GtkBuilder file and instantiate its widgets:
Glib::RefPtr<Gtk::Builder> builder = Gtk::Builder::create_from_file("dsg.glade", "mainwindow");
效果更好。然后我得到我的小部件
Gtk::Button *sf = 0;
builder->get_widget("button", sf);
现在怎么办?我发现的连接信号处理程序的每个示例都不是由 gtkbuilder 构建的。如果您实例化自己的类来表示/处理/渲染按钮,则很容易将信号处理程序连接到它,但我使用的是 gtkbuilder,并且我不知道如何编写可以附加到我的小部件的函数,因为我不是创建按钮对象的人,所以 gtkbuilder 是。
我是否让 gtkbutton 的子类编写我的函数然后指向它?但我的类没有被 gtkbuilder 实例化。
我就是不明白。帮助?
I make my interface with glade. Works great.
I write a tiny little main function which calls gtkbuilder and renders everything in the glade file.
Gtk::Main kit(num, opts);
// Load the GtkBuilder file and instantiate its widgets:
Glib::RefPtr<Gtk::Builder> builder = Gtk::Builder::create_from_file("dsg.glade", "mainwindow");
Works even better. Then I get my widget
Gtk::Button *sf = 0;
builder->get_widget("button", sf);
Now what? Every example I've found to connect a signal handler is not built by gtkbuilder. If you instantiate your own class to represent/handle/render a button it's easy to connect a signal handler to it, but I'm using gtkbuilder and I don't see how to write a function that I can then attach to my widget, since I wasn't the one creating the button object, gtkbuilder was.
Do I make a subclass of gtkbutton write my function then point to that? But my class isn't being instantiated by gtkbuilder.
I just don't get it. Help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你并没有遗漏一些明显的东西。 gtkmm 似乎没有提供
gtk_builder_connect_signals()
函数的 C++ 版本,这就是你在 C 中的做法。我做了一些 Google 搜索,但我无法弄清楚为什么他们会把它排除在外。您可以像这样直接访问 C 函数:
You're not missing something obvious. It seems that gtkmm doesn't provide a C++ version of the
gtk_builder_connect_signals()
function, which is how you do it in C. I've done a little Google searching, but I can't figure out why they would leave it out.You can access the C function directly like this:
你应该像这样使用你自己的按钮类:
现在在你的主代码中的某个地方(我把它放在我的核心类中,它是 Gtk::Window 的 public ):
我在官方 gtkmm 手册 一个月前并在我的 GUI 中成功使用它应用程序。
我希望这有帮助。
you should use your own button class like this:
Now somewhere in your main code (I put it in my Core class who is of public of Gtk::Window):
I found this in the official gtkmm manual some month ago and using it successfully in my GUI applications.
I hope this helps.