Re: Setting Font Faces and Sizes




On Jan 6, 2007, at 11:11 AM, rahed wrote:

muppet <scott asofyet org> writes:

That doesn't help you for entries, but why are you wanting to change
the font in an entry?

I just tried to change the font for an entry widget. For some reason I
want to change the weight.

$weight = $gladexml->get_widget('entry1')->get_style->font_desc- >get_weight;

print Dumper($weight);

$gladexml->get_widget('entry1')->get_style->font_desc->set_weight ('bold');

$weight = $gladexml->get_widget('entry1')->get_style->font_desc- >get_weight;

print Dumper($weight);

But it always prints 'normal'. What do I neglect?

It looks like you actually got a copy of the font description from Gtk2::Style::font_desc, which means your changes aren't happening to the object in place. Odd. Try using modify_font(), instead:


#!/usr/bin/perl -w
use Gtk2 -init;

my $window = Gtk2::Window->new;
$window->ensure_style;

my $fontdesc = $window->get_style->font_desc;
dumpit ("before", $fontdesc, $window);

$fontdesc->set_weight ("bold");
dumpit ("after1", $fontdesc, $window);

$window->modify_font ($fontdesc);
dumpit ("after2", $fontdesc, $window);


sub dumpit {
        my ($label, $fontdesc, $widget) = @_;
        printf "%10s:  %s  %10s   %s  %10s\n",
               $label, $fontdesc, $fontdesc->get_weight,
               $widget->get_style->font_desc,
               $widget->get_style->font_desc->get_weight;
}

__END__






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