c - How to center a dialog window on the main window in GTK? -
i want print small warning messages. achieve that, i'm creating new window , want centered on main window. far i've tried setting parent gtk_widget_set_parent
, using gtk_window_popup
, gtk_window_toplevel
nothing worked.
how center window on main window?
here's code function:
static void pop_warning(char *title, char *text) { gtkwidget *warning_window; gtkwidget *box; gtkwidget *label; gtkwidget *button; warning_window = gtk_window_new(gtk_window_toplevel); gtk_window_set_title(gtk_window(warning_window), title); g_signal_connect(gtk_window(warning_window), "destroy", g_callback(gtk_widget_destroy), null); gtk_container_set_border_width(gtk_container(warning_window), 20); gtk_window_set_resizable(gtk_window(warning_window), false); //window main window gtk_widget_set_parent(warning_window, window); gtk_window_set_position(gtk_window(warning_window), gtk_win_pos_center_on_parent); box = gtk_box_new(gtk_orientation_vertical, 10); gtk_container_add(gtk_container(warning_window), box); label = gtk_label_new(text); gtk_box_pack_start(gtk_box(box), label, true, false, 0); button = gtk_button_new_with_label("ok"); g_signal_connect_swapped(button, "clicked", g_callback(gtk_widget_destroy), warning_window); gtk_box_pack_start(gtk_box(box), button, true, false, 0); gtk_widget_show_all(warning_window); }
gtk_window_set_position(gtk_window(warning_window), gtk_win_pos_center_on_parent);
only works if first call
gtk_window_set_transient_for(gtkwindow *window, gtkwindow *parent);
as mentioned explicitly in documentation.
you try use gtk_win_pos_center_always
has not above mentioned constrain - @ least not according docs.
Comments
Post a Comment