Re: Label Colors
| From: | Gonzalo Monzón | Date: | Sun, 12 Dec 2004 21:21:40 +0000 |
| Subject: | Re: Label Colors | ||
| References: | 1 | Groups: | php.gtk.general |
| Request: | Send a blank email to php-gtk-general+get-5339@lists.php.net to get a copy of this message | ||
Steven Norder wrote:
I have spent the last day or so trying to figure out how to set the color/font on a label which come to find out it was in the main docs just couldn't find it right away. My question is, is there any way to make to the text of two different labels different colors? every way i try to do it it seems to just change all the labels to same color/font this is my latest try and i get nothing they are all the same color they all go orange $label[1] = &new GtkLabel("This is my label 1"); $label[2] = &new GtkLabel("This is my label 2"); $style[1] = $label[1]->get_style(); $font[1] = gdk::font_load("-*-helvetica-medium-r-normal--*-180-*-*-*-*-*-*"); $style[1]->font = $font[1]; $color[1] = &new GdkColor( 'blue');; $style[1]->fg[GTK_STATE_NORMAL] = $color[1]; $label[1]->set_style( $style[1]); $style[2] = $label[2]->get_style(); $font[2] = gdk::font_load("-*-helvetica-medium-r-normal--*-180-*-*-*-*-*-*"); $style[2]->font = $font[2]; $color[2] = &new GdkColor( 'orange');; $style[2]->fg[GTK_STATE_NORMAL] = $color[2]; $label[2]->set_style( $style[2]); any help would be very very nice i noticed someone asked this question like 6 months ago but i couldnt' find a response if it is somewhere on the site i am sorry for missing it but i have looked everywhere i can and browsed the archives of this mailing list. Steven ------------------------------------------------------------------------ No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.289 / Virus Database: 265.4.8 - Release Date: 12/8/2004 Hi Steven!I think your're not doing it well... you must do a copy of the style ie. getting it from the gtk::widget_get_default_style or with $widget->get_style and then doing a copy of it before setting it modified... These two code pieces work well for me: First example: getting the style from gtk directly...
$label4=&new GtkLabel(' Pegar Ctrl+V');
$appStyle = gtk::widget_get_default_style();
$appStyle->fg[GTK_STATE_NORMAL]=$color;
$label4->set_style($appStyle);
or another way, getting the actual widget's style:
$cstyle=$this->en_reloj->get_style();
$bstyle=$cstyle->copy();
$bfont=gdk::font_load("-*-arial-bold-r-normal--*-120-*-*-*-*-iso8859-1");
$bstyle->font=$bfont;
$negro = &new GdkColor('#000000');
$bstyle->fg[GTK_STATE_INSENSITIVE] = $negro;
$this->en_reloj->set_style($bstyle);
Sincerely,
Gonzalo Monzón