GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Mon Apr 21, 2014 7:09 am

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: How can I change color gtkbutton?
PostPosted: Mon Jun 25, 2012 4:12 pm 
Offline
Familiar Face

Joined: Fri Jul 15, 2011 11:41 am
Posts: 12
Hello,
I'm using GTK + version 3 and I'm trying to change the color of a GtkButton with gtk_widget_modigy_bg but not changed. I have a button created with glade and then I want to change the color of GtkButton but does not change.


Top
 Profile  
 
 Post subject: Re: How can I change color gtkbutton?
PostPosted: Mon Jun 25, 2012 4:36 pm 
Offline
GTK+ Guru

Joined: Fri Mar 25, 2011 5:16 pm
Posts: 176
Location: USA
You don't say what version of gtk3 your using but gtk_widget_modify_bg has been depreciated (Not for use in ANY of the gtk3 series.). Use gtk_widget_override_background_color instead.
http://developer.gnome.org/gtk3/3.4/GtkWidget.html#gtk-widget-modify-fg
If you're using a different version of gtk3, maybe 3.2 for instance, just change the "3.4" in the link I've posted to "3.2". That's true for all the documentation.

But you might consider just using CSS. I've post several tutorials in the tutorials sections.
http://www.gtkforums.com/viewtopic.php?f=3&t=988&p=195278&hilit=GTK3+with+CSS#p195278


Top
 Profile  
 
 Post subject: Re: How can I change color gtkbutton?
PostPosted: Mon Jun 25, 2012 10:22 pm 
Offline
Familiar Face

Joined: Fri Jul 15, 2011 11:41 am
Posts: 12
Ok, thanks but I have used css but does not change, I attached the code. I use version 3.4.

theme.css
Code:
GtkWindow {
   background-image: url("fondo.jpg");
}

GtkButton {
   background-color: white;
}


ejemplo.c


Code:
#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.h>  /* for css */

typedef struct {

   GtkWidget *window;   
   GtkWidget *box;   
   GtkWidget *button_1;   
   GtkWidget *button_2;   
   GtkWidget *button_close;   

   GtkWidget *button;   
} example;

int main(int argc, char *argv[]) {

   example test;

   GtkBuilder *builder;

/*---- CSS ------------------*/
  GtkCssProvider *provider;
  GdkDisplay *display;
  GdkScreen *screen;
/*---------------------------*/

   //Inicio
   gtk_init (&argc, &argv);

   builder = gtk_builder_new();
   gtk_builder_add_from_file(builder, "test-gtkbuilder.glade", NULL);
   test.window = GTK_WIDGET (gtk_builder_get_object (builder, "window1"));
   test.box = GTK_WIDGET (gtk_builder_get_object (builder, "box1"));

   test.button_1 = GTK_WIDGET (gtk_builder_get_object (builder, "eventbox2"));
   test.button_j2 = GTK_WIDGET (gtk_builder_get_object (builder, "button2"));
   test.button = GTK_WIDGET (gtk_builder_get_object (builder, "button3"));
   test.button_close = GTK_WIDGET (gtk_builder_get_object (builder, "button5"));


/* ----------------- CSS ----------------------------------------------------------------------------------------------*/
  provider = gtk_css_provider_new ();
  display = gdk_display_get_default ();
  screen = gdk_display_get_default_screen (display);
  gtk_style_context_add_provider_for_screen (screen, GTK_STYLE_PROVIDER (provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);

  gsize bytes_written, bytes_read;

  const gchar* home = "theme.css";

  GError *error = 0;

  gtk_css_provider_load_from_path (provider,
                                  g_filename_to_utf8(home, strlen(home), &bytes_read, &bytes_written, &error),
                                  NULL);
  g_object_unref (provider);
/* --------------------------------------------------------------------------------------------------------------------*/


 
   g_signal_connect (G_OBJECT (test.button_close), "clicked", G_CALLBACK (callback_close), NULL);
   g_signal_connect (G_OBJECT (test.window), "delete_event", G_CALLBACK (gtk_main_quit), NULL);
   g_signal_connect (G_OBJECT (test.window), "destroy", G_CALLBACK (gtk_main_quit), NULL);

   gtk_window_maximize (GTK_WINDOW (test.window));
   gtk_widget_show_all(test.window);

   gtk_main ();

   //Cerrar MYSQL
   mysql_close(test.con);

   return 0;
}


Top
 Profile  
 
 Post subject: Re: How can I change color gtkbutton?
PostPosted: Mon Jun 25, 2012 11:40 pm 
Offline
GTK+ Guru

Joined: Fri Mar 25, 2011 5:16 pm
Posts: 176
Location: USA
1) Are you receiving any error messages or does the button just not change color?
2) Does the background image show up?
3) Try talking out the mysql

I don't see any other problem. Can you post your builder code.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group