Change button color in button-press-event

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

 



Hello,

I am using Gtk+ 2.10.14, r8.

I have a dialog with several buttons (GtkButton).
When a button is pressed, I want to change its color to blue, and when it is released to restore its original color.

The code I use is shown below.
I do get BUTTON PRESS and BUTTON RELEASE messages, but the button color does not change.
It seems like the button does not get re-painted.
I tried calling re-drawing the button in the ButtonPressCallback() by calling gtk_widget_queue_draw() but that made no difference.

Any ideas will be appreciated.

Thanks,

D.



gboolean ButtonPressCallback(
        GtkWidget      *widget,
        GdkEventButton *event,
        gpointer        user_data)
{
    printf("BUTTON PRESS\n");
    GdkColor color;
    gdk_color_parse ("blue", &color);
    gtk_widget_modify_bg(widget, GTK_STATE_PRELIGHT, &color);
    gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, &color);
    return FALSE;
}

static gboolean ButtonReleaseCallback(
    GtkWidget      *widget,
    GdkEventButton *event,
    gpointer        user_data)
{
    printf("BUTTON RELEASE\n");
    gtk_widget_modify_bg(widget, GTK_STATE_PRELIGHT, NULL);
    gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, NULL);
    return FALSE;
}


// My init function
...
g_signal_connect(
pButton, "button-press-event",
GTK_SIGNAL_FUNC(ButtonPressCallback), 0);

g_signal_connect(
pButton, "button-release-event",
GTK_SIGNAL_FUNC(ButtonReleaseCallback), 0);
...
_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux