I tried to add GTKButton to a GtkListStore to edit data in each row... The button doesn't appear, and i get this error message : "GLib-GObject-WARNING **: unable to set property text' of typegchararray' from value of type `GtkButton'".
here is my code :
#include <gtk/gtk.h>
GtkTreeModel * create_and_fill_model()
{
GtkListStore *store;
GtkTreeIter iter;
store = gtk_list_store_new (9,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_UINT,
G_TYPE_FLOAT,
GTK_TYPE_BUTTON);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
0, "A5525654",
1, "DFFFCCN",
2, "Doe",
3, "John",
4, "M",
5, "casablanca",
6, 2014,
7, 18.22,
8,GTK_BUTTON(gtk_button_new_with_label("EDIT")),
-1);
return GTK_TREE_MODEL (store);
}
GtkWidget * create_view_and_model()
{
GtkCellRenderer *renderer;
GtkTreeModel *model;
GtkWidget *view;
view = gtk_tree_view_new ();
char colonne[9][16] =
{
"CIN",
"CNE",
"Nom",
"Prenom",
"Sexe",
"Etablissement",
"Annee Obt",
"Note Gener",
"Edit"
};
int i;
for(i=0; i<9; i++)
{
renderer = gtk_cell_renderer_text_new ();
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (view),
-1,
colonne[i],
renderer,
"text", i,
NULL);
}
model = create_and_fill_model ();
gtk_tree_view_set_model (GTK_TREE_VIEW (view), model);
g_object_unref (model);
return view;
}
int main (int argc, char **argv)
{
GtkWidget *window;
GtkWidget *view;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
g_signal_connect (window, "delete_event", gtk_main_quit, NULL);
view = create_view_and_model ();
gtk_container_add (GTK_CONTAINER (window), view);
gtk_widget_show_all (window);
gtk_main ();
return 0;
}
Source code that works:
#include <gtk/gtk.h>
GtkTreeModel * create_and_fill_model()
{
GtkListStore *store;
GdkPixbuf *icon;
GError *error = NULL;
GtkTreeIter iter;
store = gtk_list_store_new (9,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_UINT,
G_TYPE_FLOAT,
GDK_TYPE_PIXBUF);
gtk_list_store_append (store, &iter);
icon = gdk_pixbuf_new_from_file("edit.png", &error);
gtk_list_store_set (store, &iter,
0, "A5525654",
1, "DFFFCCN",
2, "Doe",
3, "John",
4, "M",
5, "casablanca",
6, 2014,
7, 18.22,
8,icon,
-1);
if (error)
{
g_warning ("probleme de chargement de l'icone : %s\n", error->message);
g_error_free(error);
error = NULL;
}
return GTK_TREE_MODEL (store);
}
GtkWidget * create_view_and_model()
{
GtkCellRenderer *renderer;
GtkTreeModel *model;
GtkWidget *view;
view = gtk_tree_view_new ();
char colonne[9][16] =
{
"CIN",
"CNE",
"Nom",
"Prenom",
"Sexe",
"Etablissement",
"Annee Obt",
"Note Gener",
"Edit"
};
int i;
for(i=0; i<9; i++)
{
if(i==8)
{
renderer = gtk_cell_renderer_pixbuf_new();
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (view),
-1,
colonne[i],
renderer,
"pixbuf", i,
NULL);
}
else
{
renderer = gtk_cell_renderer_text_new ();
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (view),
-1,
colonne[i],
renderer,
"text", i,
NULL);
}
}
model = create_and_fill_model ();
gtk_tree_view_set_model (GTK_TREE_VIEW (view), model);
g_object_unref (model);
return view;
}
int main (int argc, char **argv)
{
GtkWidget *window;
GtkWidget *view;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
g_signal_connect (window, "delete_event", gtk_main_quit, NULL);
view = create_view_and_model ();
gtk_container_add (GTK_CONTAINER (window), view);
gtk_widget_show_all (window);
gtk_main ();
return 0;
}
Your implementation of placing a button in tree view cannot work as written. You are creating a text renderer for all the columns, and a text renderer obviously cannot draw a GTK button. (You get the error while setting the text property on the renderer based on a button-typed column in the model.)
One simple way of placing a button in a tree view is by putting a clickable image in the cell, as shown by this answer.
Related
When I right-click the header, the event responds normally
When I right-click the row, the event does not respond
What I do is:
new GtkGesture instance and register released event,call gtk_widget_add_controller bind GtkGesture and GtkTreeView
what I want is right-click the row and pop context menu
what can I to do let the row respond normally,use C and GTK4 code,here is my code:
#include <gtk/gtk.h>
static void
on_released(GtkGestureClick *gesture,
int n_press,
double x,
double y,
GtkWidget *widget)
{
GMenu *menu = g_menu_new();
g_menu_append(menu, "test", "win.test");
GtkWidget *popmenu = gtk_popover_menu_new_from_model(G_MENU_MODEL(menu));
gtk_popover_set_has_arrow(GTK_POPOVER(popmenu), FALSE);
gtk_widget_set_parent(popmenu, widget);
gtk_popover_set_pointing_to(GTK_POPOVER(popmenu), &(const GdkRectangle){x, y, 1, 1});
gtk_popover_popup(GTK_POPOVER(popmenu));
}
void set_font_for_display_with_pango_font_desc(GtkWindow *win)
{
PangoFontDescription *pango_font_desc = pango_font_description_from_string("Monospace");
const char *family = pango_font_description_get_family(pango_font_desc);
char *css = g_strdup_printf("window,label{font-family: \"%s\";font-style: %s;font-weight:%s;font-size:%dpt;} treeview.view label{color:black;}",
family, "normal", "900", 15);
GdkDisplay *display = gtk_widget_get_display(GTK_WIDGET(win));
GtkCssProvider *provider = gtk_css_provider_new();
gtk_css_provider_load_from_data(provider, css, -1);
gtk_style_context_add_provider_for_display(display, GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_USER);
}
static void
activate(GtkApplication *app,
gpointer user_data)
{
GtkWidget *window;
GtkGesture *gesture;
GtkTreeIter iter;
window = gtk_application_window_new(app);
gtk_window_set_title(GTK_WINDOW(window), "Claim Right Button Click “released”");
gtk_window_set_default_size(GTK_WINDOW(window), 400, 400);
GtkWidget *scrollwin = gtk_scrolled_window_new();
gtk_widget_set_vexpand(scrollwin, TRUE);
gtk_widget_set_hexpand(scrollwin, TRUE);
gtk_window_set_child(GTK_WINDOW(window), scrollwin);
GtkTreeModel *model = GTK_TREE_MODEL(gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING, -1));
gtk_list_store_insert(GTK_LIST_STORE(model), &iter, -1);
gtk_list_store_set(GTK_LIST_STORE(model), &iter, 0, "1", 1, "bill", -1);
GtkWidget *treeview1 = gtk_tree_view_new_with_model(model);
gtk_widget_set_vexpand(treeview1, TRUE);
gtk_widget_set_hexpand(treeview1, TRUE);
GtkCellRenderer *renderer = gtk_cell_renderer_text_new();
GtkTreeViewColumn *col = gtk_tree_view_column_new_with_attributes("id", renderer, "text", 0, NULL);
gtk_tree_view_column_set_min_width(col,100);
gtk_tree_view_append_column(GTK_TREE_VIEW(treeview1), col);
col = gtk_tree_view_column_new_with_attributes("name", renderer, "text", 1, NULL);
gtk_tree_view_column_set_min_width(col,200);
gtk_tree_view_append_column(GTK_TREE_VIEW(treeview1), col);
g_object_unref(model);
gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(scrollwin), treeview1);
/* Register for mouse right button click "pressed" and "released" events on inner widget*/
gesture = gtk_gesture_click_new();
gtk_gesture_single_set_button(GTK_GESTURE_SINGLE(gesture), 3);
g_signal_connect(gesture, "released", G_CALLBACK(on_released), treeview1);
gtk_widget_add_controller(treeview1, GTK_EVENT_CONTROLLER(gesture));
set_font_for_display_with_pango_font_desc(GTK_WINDOW(window));
gtk_widget_show(window);
}
int main(int argc,
char **argv)
{
GtkApplication *app;
int status;
app = gtk_application_new("com.test", G_APPLICATION_FLAGS_NONE);
g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);
status = g_application_run(G_APPLICATION(app), argc, argv);
g_object_unref(app);
return status;
}
I am trying to set a custom GtkAccelLabel to my GtkMenuItem, though I cant figure out how to use that widget ... for me just nothing is displayed.
Why are the following calls wrong / not sufficient ?
...
fileMi = gtk_menu_item_new_with_label("File");
label = gtk_accel_label_new ("Strg+X");
gtk_accel_label_set_accel_widget (label, quitMi);
...
Here a complete reproducer:
int main(int argc, char *argv[]) {
GtkWidget *window;
GtkWidget *vbox;
GtkWidget *menubar;
GtkWidget *fileMenu;
GtkWidget *fileMi;
GtkWidget *quitMi;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 300, 200);
gtk_window_set_title(GTK_WINDOW(window), "Simple menu");
vbox = gtk_vbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(window), vbox);
GtkAccelGroup *accel_group;
// Create a GtkAccelGroup and add it to the window.
accel_group = gtk_accel_group_new ();
gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);
menubar = gtk_menu_bar_new();
fileMenu = gtk_menu_new();
fileMi = gtk_menu_item_new_with_label("File");
quitMi = gtk_menu_item_new_with_label("Quit");
gtk_menu_item_set_submenu(GTK_MENU_ITEM(fileMi), fileMenu);
gtk_menu_shell_append(GTK_MENU_SHELL(fileMenu), quitMi);
gtk_menu_shell_append(GTK_MENU_SHELL(menubar), fileMi);
gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, FALSE, 0);
GtkWidget *label = gtk_accel_label_new ("Strg+X");
gtk_accel_label_set_accel_widget (label, quitMi);
gtk_accel_label_refetch (label);
g_signal_connect(G_OBJECT(window), "destroy",
G_CALLBACK(gtk_main_quit), NULL);
g_signal_connect(G_OBJECT(quitMi), "activate",
G_CALLBACK(gtk_main_quit), NULL);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
Hah, I found a solution .. though no idea if it actually should be done like that.
The key is, that there is already a gtk_accel_label on the MenuItem, and I can modify it:
for (GList* lp = gtk_container_get_children (quitMi); lp != NULL; lp = lp->next)
{
if (GTK_IS_ACCEL_LABEL (lp->data))
gtk_accel_label_set_accel (lp->data, GDK_KEY_0, GDK_MOD1_MASK);
}
I'm trying my hand at writing a C program using GTK (GTK 3 to be precise) (up to now, my experience has mainly been using ObjC, Visual Studio and so on but Cross Platform FTW!)
I need to have a scrollable table, so I've been playing with some of the example code that I've found on the web. The only table code that I've been able to find so far grows the window, and pushes any other elements down the screen as rows are added. I need the table to be a fixed size and to scroll (leaving the header row visible, of course).
This is what I've got so far:
#include <gtk/gtk.h>
enum {
FILE_NAME,
FILE_OFFSET,
FILE_SIZE,
FILE_DESCRIPTION, /* Not used by the view, maybe used elsewhere */
COLOR, /* Just to show how the model can affect the view */
N_COLUMNS
};
void add_row (GtkWidget *widget, gpointer data) {
gtk_list_store_insert_with_values(data, NULL, -1,
COLOR, "blue",
-1);
}
void destroy (GtkWidget *widget,gpointer data) {
gtk_main_quit ();
}
gint main(gint argc, gchar **argv)
{
GtkListStore* model;
GtkWidget* view;
GtkTreeViewColumn* column;
gtk_init(&argc, &argv);
/* MODEL */
model = gtk_list_store_new(N_COLUMNS,
G_TYPE_STRING, /* FILE_NAME */
G_TYPE_UINT, /* FILE_OFFSET */
G_TYPE_UINT, /* FILE_SIZE */
G_TYPE_STRING, /* FILE_DESCRIPTION */
G_TYPE_STRING /* COLOR */
);
gtk_list_store_insert_with_values(model, NULL, -1,
FILE_NAME, "test name",
FILE_OFFSET, 0,
FILE_SIZE, 10,
-1);
gtk_list_store_insert_with_values(model, NULL, -1,
FILE_NAME, "Dummy",
FILE_OFFSET, 123,
COLOR, "black",
-1);
/* VIEW */
view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model));
g_object_unref(model);
column = gtk_tree_view_column_new_with_attributes("Name",
gtk_cell_renderer_text_new(),
"text", FILE_NAME,
"background", COLOR,
NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);
column = gtk_tree_view_column_new_with_attributes("Offset",
gtk_cell_renderer_spin_new(),
"text", FILE_OFFSET,
NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);
column = gtk_tree_view_column_new_with_attributes("Size",
gtk_cell_renderer_text_new(),
"text", FILE_SIZE,
NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);
GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "Test App");
gtk_window_set_default_size (GTK_WINDOW (window), 400, 600);
g_signal_connect (window, "destroy", G_CALLBACK (destroy), NULL);
/* Button */
GtkWidget *button;
button = gtk_button_new_with_label ("Add row");
g_signal_connect (button, "clicked", G_CALLBACK(add_row), model);
/* Layoutbox */
GtkWidget *layout_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
gtk_container_add (GTK_CONTAINER (window), layout_box);
/* Scrollview */
GtkWidget *scrollview = gtk_layout_new(NULL, NULL);
g_object_set(G_OBJECT(scrollview), "app-paintable", TRUE, NULL);
gtk_widget_add_events (scrollview, GDK_ALL_EVENTS_MASK);
gtk_layout_put (GTK_LAYOUT (scrollview), view, 10, 10);
gtk_widget_set_size_request(view, 300, 200);
gtk_container_add (GTK_CONTAINER (layout_box), scrollview); //view
gtk_widget_show_all(window);
GdkWindow *win = gtk_layout_get_bin_window (GTK_LAYOUT(scrollview));
gdk_window_set_events (win, gdk_window_get_events (win) | GDK_STRUCTURE_MASK);
gtk_main ();
return 0;
}
It is a bit of a mess at the moment! My apologies - that's partly inexperience with GTK and mostly multiple iterations in trying to get it to work.
At the moment the table displays very briefly before disappearing (that interesting behaviour only started when I tried to make it into a scroll box).
Note, I only want the table to scroll - not the entire window. In a perfect world, the table would be the width of the window (or layout that contains it) but limited to n pixels high, with a scrollbar if the height exceeds that limit.
I'm a simple guy though, so I also want any solution to be simple - so that I can wrap my brain around it!
Any ideas?
You are using a GtkLayout but the widget to use for scrolling is GtkScrolledWindow.
Here's the adapted code:
#include <gtk/gtk.h>
enum {
FILE_NAME,
FILE_OFFSET,
FILE_SIZE,
FILE_DESCRIPTION, /* Not used by the view, maybe used elsewhere */
COLOR, /* Just to show how the model can affect the view */
N_COLUMNS
};
void add_row (GtkWidget *widget, gpointer data) {
gtk_list_store_insert_with_values(data, NULL, -1,
COLOR, "blue",
-1);
}
void destroy (GtkWidget *widget,gpointer data) {
gtk_main_quit ();
}
gint main(gint argc, gchar **argv)
{
GtkListStore* model;
GtkWidget* view;
GtkTreeViewColumn* column;
gtk_init(&argc, &argv);
/* MODEL */
model = gtk_list_store_new(N_COLUMNS,
G_TYPE_STRING, /* FILE_NAME */
G_TYPE_UINT, /* FILE_OFFSET */
G_TYPE_UINT, /* FILE_SIZE */
G_TYPE_STRING, /* FILE_DESCRIPTION */
G_TYPE_STRING /* COLOR */
);
gtk_list_store_insert_with_values(model, NULL, -1,
FILE_NAME, "test name",
FILE_OFFSET, 0,
FILE_SIZE, 10,
-1);
gtk_list_store_insert_with_values(model, NULL, -1,
FILE_NAME, "Dummy",
FILE_OFFSET, 123,
COLOR, "black",
-1);
/* VIEW */
view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model));
g_object_unref(model);
column = gtk_tree_view_column_new_with_attributes("Name",
gtk_cell_renderer_text_new(),
"text", FILE_NAME,
"background", COLOR,
NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);
column = gtk_tree_view_column_new_with_attributes("Offset",
gtk_cell_renderer_spin_new(),
"text", FILE_OFFSET,
NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);
column = gtk_tree_view_column_new_with_attributes("Size",
gtk_cell_renderer_text_new(),
"text", FILE_SIZE,
NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);
GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "Test App");
gtk_window_set_default_size (GTK_WINDOW (window), 400, 600);
g_signal_connect (window, "destroy", G_CALLBACK (destroy), NULL);
/* Button */
GtkWidget *button;
button = gtk_button_new_with_label ("Add row");
g_signal_connect (button, "clicked", G_CALLBACK(add_row), model);
/* Layoutbox */
GtkWidget *layout_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
gtk_container_add (GTK_CONTAINER (window), layout_box);
/* Scrollview */
GtkWidget *scrollview = gtk_scrolled_window_new(NULL, NULL);
gtk_container_add (GTK_CONTAINER (scrollview), view);
/* expand to fill all available space left in the window */
gtk_widget_set_hexpand(scrollview, TRUE);
gtk_widget_set_vexpand(scrollview, TRUE);
gtk_container_add (GTK_CONTAINER (layout_box), scrollview); //view
gtk_container_add (GTK_CONTAINER (layout_box), button);
gtk_widget_show_all(window);
gtk_main ();
return 0;
}
here is my problem: I just put a gtk_text_view_new() in a gtk_scrolled_window_new(). Now when I write in the textField, at the end of the gtk_widget_set_size_request->high the text is hidden and the whole text does not scroll upwards as I want.
-> The textfield should automatically scroll upwards and show its last line.
#include <gtk/gtk.h>
int main(int argc, char **argv) {
gtk_init(&argc, &argv);
GtkWidget *window;
GtkWidget *myGrid;
GtkWidget *scollwindow;
GtkWidget *textField;
GtkTextBuffer *buffer;
GtkWidget *quitbutton;
//---------------------widgets-------------------------------
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
quitbutton = gtk_button_new_with_label("QUIT");
myGrid = gtk_grid_new ();
//---------------------textField-------------------------------
textField = gtk_text_view_new ();
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (textField));
gtk_text_buffer_set_text (buffer, "Hello, this is some text, ", -1);
//---------------------insert textField in scrollwindow-------------------------------
scollwindow = gtk_scrolled_window_new (NULL,NULL);
gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scollwindow), textField);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scollwindow), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
//---------------------widgets size-------------------------------
gtk_widget_set_size_request (scollwindow, 200, 200);
gtk_widget_set_size_request (window, 200, 200);
//---------------------grid attache-------------------------------
gtk_grid_attach(GTK_GRID(myGrid), scollwindow, 0, 0, 1, 1);
gtk_grid_attach(GTK_GRID(myGrid), quitbutton, 0, 1, 1, 1);
//---------------------add to grid-------------------------------
gtk_container_add(GTK_CONTAINER(window), myGrid);
//---------------------signals-------------------------------
g_signal_connect(quitbutton, "clicked", G_CALLBACK(gtk_main_quit), NULL);
g_signal_connect(window, "destroy", gtk_main_quit, NULL);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
Got it, just change line " gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scollwindow), textField);" to "gtk_container_add (GTK_CONTAINER(scollwindow), textField);"
I have a program using pthreads. I want add an interface using gtk2.0, but have a problem with drawing on window. When I call g_signal_connect(G_OBJECT(window), "configure_event",G_CALLBACK(draw_things), NULL);
lines which I draw appear and at once disappear. If I move a window calling function
gtk_window_move (GTK_WINDOW(widget), 10,10);
or by means of a mouse, lines appear. If I call g_signal_connect(G_OBJECT(window), "expose_event", G_CALLBACK(draw_things), NULL); my lines are displayed correctly, but buttons and labels are not displayed. My code looks like this:
int main(int argc, char *argv[]){
pthread_t tr1;
pthread_t tr2;
pthread_t *trs;
int rc = 0;
type j;
int16_t *id;
type Stop_Point;
GtkWidget *window;
GtkWidget *button;
GtkWidget *table;
GtkWidget *drawing_area;
g_thread_init (NULL);
gdk_threads_init ();
gdk_threads_enter ();
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_widget_set_size_request(window, width/1.6, height/1.33);
gtk_window_set_position(GTK_WINDOW(window), -1);
gtk_window_set_title (GTK_WINDOW (window), "Window");
g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (delete_event), NULL);
gtk_container_set_border_width (GTK_CONTAINER (window), 2);
table = gtk_table_new ( width/1.6, height/1.33, TRUE);
gtk_container_add (GTK_CONTAINER (window), table);
button = gtk_button_new_with_label ("next >>");
gtk_table_attach_defaults (GTK_TABLE (table), button, 1110, 1190, 750, 790);
gtk_widget_show (button);
button = gtk_button_new_with_label ("<< prev");
gtk_table_attach_defaults (GTK_TABLE (table), button, 1020, 1100 , 750, 790);
gtk_widget_show (button);
rc = pthread_create(&tr1, NULL, tr1_func, &id);
rc = pthread_create(&Generator, NULL, tr2_func, &Stop_Point);
trs = (pthread_t*)malloc(Num * sizeof(pthread_t));
for(j = 0; j < Num; j++) {
rc = pthread_create(trs + j, NULL, trs_func, id + j);
}
// g_signal_connect(G_OBJECT(window), "configure-event", GTK_SIGNAL_FUNC(draw_things), NULL);
g_signal_connect(G_OBJECT(window), "expose_event", G_CALLBACK(draw_things), NULL);
gtk_widget_show_all (window);
gtk_main ();
gdk_threads_leave ();
return 0;
}
Fnction for drawing looks like this
gboolean draw_things(GtkWidget *widget, GdkEventExpose *event, gpointer data) {
GdkGC *gc;
gc=gdk_gc_new(GDK_DRAWABLE(widget->window));
gdk_gc_set_line_attributes(gc, 5, GDK_LINE_SOLID, GDK_CAP_ROUND, GDK_JOIN_ROUND);
gdk_draw_line(GDK_DRAWABLE(widget->window), gc, 5, 35, 1200, 35);
gdk_draw_line(GDK_DRAWABLE(widget->window), gc, 1170, 45, 1200, 35);
gdk_draw_line(GDK_DRAWABLE(widget->window), gc, 1170, 25 , 1200, 35);
// gtk_window_move (GTK_WINDOW(widget), 1,1);
return TRUE;
}
Any help is welcomed, because now I use "configure_event" and call gtk_window_move (GTK_WINDOW(widget), 0,0); every time when I need to draw the picture.