我对GTK3很陌生。 我创建了一个EventBoxes数组,它们每个都包含一个图像。所有框都链接到相同的on_button_pressed方法。当用户单击图像时,我想获取事件框中显示的图像的文件名。有什么办法可以做到?
感谢所有帮助。
----编辑1 -------------------------
Code:
//In my header file, I've declared:
class Window : public Gtk::Window{
//....some other window elements....
Gtk::EventBox portraits[13];
Gtk::Image * portraitImage[13];
};
//In my .cc file, I've implemented:
Window::Window(){
//....creating some window elements ....
for(int i = 0; i < 13; i++){
portraitImage[i] = new Gtk::Image("empty.png");
portraits[i].signal_button_press_event().connect(sigc::mem_fun(*this,
&Window::doOnPortraitClicked));
portraits[i].set_image(*portraitImage[i]);
}
//..........some other code for displaying the window..........//
show_all_children()
}
//doOnPortraitClicked method
bool Window::doOnPortraitClicked(GdkEventButton * button){
?? GValue value = G_VALUE_INIT;
?? g_value_init (&value, G_TYPE_STRING);
?? g_object_get_property(G_OBJECT(button->get_image()), "file", &value);
?? string source = g_value_get_string(&value);
// How do I retrieve "empty.png" from the EventButton?
}