Re: changing mouse cursor over a drawing area



Jack Wei wrote:

i can change the cursor just fine over eventboxes, buttons, etc...but why
doesn't it work for drawing areas?  i used the following code...

gdk_window_set_cursor(drawing_area->window,gdk_cursor_new(GdkCursorType(120)));

anyone?  thanks in advance.

The line of code you've posted have to work
(in case you're not using gdk_pointer_grab() before),
except you have a little memory leak.

Look at code I've attached (gtk+-2.0). Push the button
and move pointer to the area above

Olexiy

#include <stdio.h>
#include <gtk/gtk.h>


static GdkCursor        *cursor=NULL;
static GdkCursorType    cursor_type=0;


void callback(GtkWidget *widget, GtkWidget *area)
{
        if (cursor)
                gdk_cursor_unref(cursor);
        if (++cursor_type >= GDK_LAST_CURSOR)
                cursor_type = 0;
        cursor = gdk_cursor_new(cursor_type);
        gdk_window_set_cursor(area->window, cursor);
}

int main(int argc, char **argv)
{
GtkWidget *window;
GtkWidget *vbox;
GtkWidget *frame;
GtkWidget *area;
GtkWidget *button;
    
        gtk_init(&argc, &argv);

        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(gtk_main_quit), window);
        gtk_container_set_border_width (GTK_CONTAINER (window), 8);

        vbox = gtk_vbox_new(FALSE, 2);
        gtk_container_add(GTK_CONTAINER(window), vbox);

        frame = gtk_frame_new(NULL);
        gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE,FALSE, 0);
        area = gtk_drawing_area_new();
        gtk_widget_set_size_request(area, 256,256);
        gtk_container_add(GTK_CONTAINER(frame), area);

        button = gtk_button_new_with_label("change cursor");
        g_signal_connect(
                        G_OBJECT(button),
                        "clicked",
                        G_CALLBACK(callback),
                        area
        );
        gtk_box_pack_start(GTK_BOX(vbox), button, FALSE,FALSE, 0);

        gtk_widget_show_all(window);
        
        gtk_main();

        return 0;
}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]