从林间空地克隆GtkWidget,以便在应用程序中可重复使用多次 [英] clone a GtkWidget from glade so it will be reusable several times in application

查看:62
本文介绍了从林间空地克隆GtkWidget,以便在应用程序中可重复使用多次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用C编写Gtk + 3应用程序.

I'm writing a Gtk+3 application in C.

用户界面由林间空地构建.

The user interface is built with glade.

我创建了一个独立的GtkBox,应在我的应用程序中的多个地方使用. 当我尝试再次使用该GtkBox时,出现以下错误:

I created an independent GtkBox that should be used in several places in my application. When I try to use that GtkBox more then once I get the following error:

(tuxmusicstudio:27491): Gtk-WARNING **: Attempting to add a widget with type GtkBox to a container of type GtkBox, but the widget is already inside a container of type GtkBox, please use gtk_widget_reparent()

我如何克隆GtkWidget,使其可以一次又一次地重复使用?

How can I clone the GtkWidget so it will be reusable again and again?

推荐答案

您不能像这样克隆小部件.要么将您的可重用小部件放入其自己的Glade文件中,然后使用GtkBuilder加载一次以上;或为所需的小部件创建一个类,并多次实例化它.

You can't clone a widget as such. Either put your reusable widget into its own Glade file and load it more than once using GtkBuilder; or create a class for the widget you want and instantiate it more than once.

这篇关于从林间空地克隆GtkWidget,以便在应用程序中可重复使用多次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆