How to change cursor to clock in GTK for C?

I use C-style GTK functions in C ++, and I cannot figure out how to set the cursor for the main window.

+3
source share
5 answers

Conducting this because the comment on getting GdkWndow has still not been answered.

For most widgets, GdkWindow can be restored as the data field of the window of the GtkWidget structure. The following code sets the cursor to the GtkWindow widget:

GtkWidget* win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
GdkCursor* watchCursor = gdk_cursor_new(GDK_WATCH);

/* set watch cursor */
gdk_window_set_cursor(win->window, watchCursor);

/* return to normal */
gdk_window_set_cursor(win->window, NULL);

GtkWindow , :

GtkWidget* win = gtk_widget_get_ancestor(someWidget, GTK_TYPE_WINDOW);
+4

gdk_window_set_cursor() GdkCursor, gdk_cursor_new_from_name().

To get GdkWindow from GtkWindow you can use gtk_widget_get_window()it because GtkWindow is a subclass of GtkWidget.

Note: this answer is an improvement over the idefixs answer (important correction + link update + minor modification to complete the answer + improved formatting), which was rejected as editing.

+1
source

Jeff's answer didn't work for me (Gtk3). So here is my solution:

GdkWindow* win = gtk_widget_get_parent_window(widget);
GdkCursor* watchCursor = gdk_cursor_new(GDK_WATCH);
gdk_window_set_cursor(win, watchCursor);
0
source

My decision:

void gtkSetCursor(GdkCursorType cursorType) {
    GdkScreen * screen = gdk_screen_get_default();
    GdkWindow * win = gdk_screen_get_root_window(screen);
    GdkCursor * cursor = gdk_cursor_new(cursorType); //http://developer.gimp.org/api/2.0/gdk/gdk-Cursors.html
    gdk_window_set_cursor(win, cursor);
    while (gtk_events_pending()) gtk_main_iteration();
}

...
gtkSetCursor(GDK_WATCH);
start your stuff here
...
end of your stuff
gtkSetCursor(GDK_LEFT_PTR);
0
source

All Articles