25
novembre
2012
Gtk trick : make a widget clickable
novembre
2012
Un article de Rachel
Pas de commentaires
Some widgets are not clickable like a button (clicked event), but have the button-press-event or event button-release-event. Unfortunately, some of these widgets do not interpret these events.
One possible solution is to include the widget in a EventBox and capture the events of this box.
The following example shows a progressbar clickable, to give a particular value to the fraction (in Vala):
EventBox eb = new EventBox();
ProgressBar bar = new ProgressBar();
eb.add(bar);
eb.button_press_event.connect(bar_clicked);
/**/
void bar_clicked(){
int x = 0;
int width = 0;
eb.get_window().get_geometry(out x,null,null,null,null);
bar.get_window().get_geometry(null,null,out width,null,null);
bar.fraction = (double)(x/width);
}
ProgressBar bar = new ProgressBar();
eb.add(bar);
eb.button_press_event.connect(bar_clicked);
/**/
void bar_clicked(){
int x = 0;
int width = 0;
eb.get_window().get_geometry(out x,null,null,null,null);
bar.get_window().get_geometry(null,null,out width,null,null);
bar.fraction = (double)(x/width);
}