GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sat Sep 20, 2014 2:01 pm

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Using RC resource files to set widget properties
PostPosted: Sat May 31, 2008 8:46 pm 
Offline

Joined: Sat May 31, 2008 8:35 pm
Posts: 2
I'm having trouble getting a resource file to set the properties of a particular widget. For example:

The code file:

int main( int argc, char **argv )
{
Gtk::RC::add_default_file( "./hello.gtkrc" );

Gtk::Main kit( argc, argv );
Gtk::Window window;

Gtk::Label label( "Hello!" );
label.set_name( "hello_label" );
label.show();
window.add( label );

Gtk::Main::run( window );

return 0;
}


The resource file, hello.gtkrc:

style "labeltest"
{
fg[ NORMAL ] = "red"
}

widget "hello_label" style "labeltest"


This doesn't seem to work. If the last line in the resource file is replaced by
class "GtkLabel" style "labeltest"
then it does work, but I don't necessarily want to apply the style to all GtkLabels, only certain ones. Does anyone know how to do this?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 01, 2008 6:34 pm 
Offline

Joined: Sat May 31, 2008 8:35 pm
Posts: 2
I managed to figure this out on my own, with the help of http://library.gnome.org/devel/gtk/2.12 ... Files.html

The widget name that follows the widget directive in a resource file has to include the complete "path" of the widget all the way up to the root window, not just the name you give the widget in the code. So if I had set the name of the GtkWindow as "main_window", the following line works

widget "main_window.hello_label" style "labeltest"

or even better, without having to give the GtkWindow a name, you could use

widget "*.hello_label" style "labeltest"

This isn't fully explained in "Foundations of GTK+ Development," and the gtkmm documentation, as usual, doesn't explain anything at all. The above reference seems to be the best explanation of how to use RC resource files.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 01, 2008 7:07 pm 
Offline
GTK+ Geek

Joined: Wed May 28, 2008 5:49 pm
Posts: 66
However if you read down to the optimization tips, a * is a nono... better go back to the window name. Since GTK has a lot of rc files to consider, you wouldn't want to be slowing it down :/


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 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:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group