Re: Changing background color for a box widget



On Mon, 5 Jun 2006 14:23:29 +0100
"Mike Martin" <redtux1 googlemail com> wrote:

Is it possible to alter the background color for a box widget. I am
not having a lot of luck

To explain I have a dynamically created hbox added to a vbox inside a frame.

In this hbox I have two widgets a label frame (a file name) and a remove button.

I would like the background to be white so there is some contrast.

I have tried with rc files and modify_bg but it doesn't seem to take.

Any ideas?

I ran into a similar problem when using themes which set a default
pixmap background. You need to set the style to "<none>" to override
the pixmap styles from a default theme you may have going. In the following,
if I comment out the lines

bg_pixmap[NORMAL] = "<none>"
bg_pixmap[INSENSITIVE] = "<none>"
bg_pixmap[ACTIVE] = "<none>"
bg_pixmap[PRELIGHT] = "<none>"

The colors will not be set. In the example, it defaults to white, with a line
below for a dark grey.

You also can use an event box to set the background colors, as shown
in the label.

#!/usr/bin/perl
use warnings;
use strict;
use Glib qw/TRUE FALSE/;
use Gtk2 '-init';

Gtk2::Rc->parse_string(<<__);

style "default"
{

bg_pixmap[NORMAL] = "<none>"
bg_pixmap[INSENSITIVE] = "<none>"
bg_pixmap[ACTIVE] = "<none>"
bg_pixmap[PRELIGHT] = "<none>"

bg[NORMAL] = { 1.0, 1.0, 1.0 }

}class "GtkWidget" style "default"

__

my $greyl = Gtk2::Gdk::Color->new (0x9999,0x9999,0x9999);
my $bluel = Gtk2::Gdk::Color->new (0,0xCCCC,0xFFFF);
my $red = Gtk2::Gdk::Color->new (0xFFFF,0,0);
my $white = Gtk2::Gdk::Color->new (0xFFFF,0xFFFF,0xFFFF);

my $window = Gtk2::Window->new('toplevel');
$window->signal_connect( destroy => sub { Gtk2->main_quit; } );

$window->set_title("Label");
my $vbox = Gtk2::VBox->new( FALSE, 5 );
$window->add($vbox);
$window->set_border_width(5);
$window->set_size_request(300,200);
#$window->modify_bg('normal',$greyl);

my $frame = Gtk2::Frame->new("Colored Label");
my $label = Gtk2::Label->new("This is a  Colored Label");
$label->modify_fg('normal', $white);

$frame->modify_bg('normal', $red);

$vbox->pack_start( $frame, FALSE, FALSE, 0 );

#used for coloring background
my $coleventb0 = Gtk2::EventBox->new();
$coleventb0->modify_bg ('normal', $bluel);
$coleventb0->set_border_width(2);

$frame->add($coleventb0);
$coleventb0->add($label);

$window->show_all;

Gtk2->main;
__END__

-- 
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html



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