问题描述
如何获取GtkImage小部件中使用的图像的文件名?
How can I get the file name of the image used in a GtkImage widget?
我有一个显示不同图像的GtkImage小部件.我希望能够单击GtkImage,确定已单击了哪个图像,即获取文件名,然后显示较大的版本.
I have a GtkImage widget that displays different images. I want to be able to click on the GtkImage, determine which image has been clicked i.e. get the file name, then display a larger version.
谢谢
推荐答案
您可以获取 g_object_get_property
.这些行中的内容:
You can get the value of "file"
property of GtkImage
using g_object_get_property
. Something on these lines:
GValue value = {0,};
/* If you have glib version 2.30 or higher use:
* GValue value = G_VALUE_INIT;
*/
g_value_init (&value, G_TYPE_STRING);
/* Assuming image is a valid GtkImage */
g_object_get_property(G_OBJECT(image), "file", &value);
printf("\n Filename = %s\n", g_value_get_string(&value));
旁注:要利用 Glib
的类型系统,应调用 g_type_init()
.由于通过 gtk_init
进行Gtk初始化,内部调用了 g_type_init()
.
Side note: To make use of the Glib
's type system, g_type_init()
should have been called. g_type_init()
is called internally as a consequence of Gtk initialization through gtk_init
.
希望这会有所帮助!
这篇关于GtkImage文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!