 |
| View previous topic :: View next topic |
| Author |
Message |
stefan
Joined: 17 Apr 2006 Posts: 35 Location: Germany
|
Posted: Fri Mar 02, 2007 11:15 pm Post subject: change text-color of checkbutton |
|
|
hi,
i'm wondering, if theres any possibility to change the color of the label of an gtkcheckbutton??
maybe someone has a clue??
if thats not possible, how about changing the background or font size or something similar??
I'm trying to mark some of my checkboxes so they are appearing different from the others, so the users knows that these are important. |
|
| Back to top |
|
 |
kksou
Joined: 06 Sep 2006 Posts: 25
|
Posted: Sat Mar 03, 2007 4:55 am Post subject: |
|
|
You mean something like this:
The code:
| Code: | <?php
$window = new GtkWindow();
$window->set_size_request(400, 240);
$window->connect_simple('destroy', array('Gtk','main_quit'));
$window->add($vbox = new GtkVBox());
require_once "php_tools.php";
// display title
$title = new GtkLabel("Change the font and set the color of checkbox label");
$title->modify_font(new PangoFontDescription("Times New Roman Italic 10"));
$title->modify_fg(Gtk::STATE_NORMAL, GdkColor::parse("#0000ff"));
$title->set_size_request(-1, 40);
$vbox->pack_start($title, 0, 0);
// setup checkboxes
$checkbox1 = setup_checkbox('checkbox 1');
$checkbox2 = setup_checkbox('checkbox 2', "Arial Bold 16");
$checkbox3 = setup_checkbox('checkbox 3', "Times New Roman Italic 20", "#0000ff");
// pack them inside vbox
$vbox->pack_start($checkbox1, 0, 0);
$vbox->pack_start($checkbox2, 0, 0);
$vbox->pack_start($checkbox3, 0, 0);
// add a status area
$vbox->pack_start($status_area = new GtkLabel('Select the checkboxes'));
$window->show_all();
Gtk::main();
// function to simplify the display of grouped radio buttons
function setup_checkbox($label, $fg='', $color='') {
$checkbox = new GtkCheckButton($label);
examine($checkbox);
$checkbox->connect('toggled', "on_toggle");
$button_label = $checkbox->child; // note 1
if ($fg!='')
$button_label->modify_font(new PangoFontDescription($fg)); // note 2
if ($color!='') {
$button_label->modify_fg(Gtk::STATE_NORMAL, GdkColor::parse($color)); // note 3
$button_label->modify_fg(Gtk::STATE_PRELIGHT, GdkColor::parse($color)); //n4 note 3
$button_label->modify_fg(Gtk::STATE_ACTIVE, GdkColor::parse($color)); //n4 note 3
}
return $checkbox;
}
// call-back function when user pressed a radio button
function on_toggle($checkbox) {
global $status_area;
$label = $checkbox->child->get_label();
global $checkbox1, $checkbox2, $checkbox3;
$status1 = $checkbox1->get_active() ? 'on' : 'off';
$status2 = $checkbox2->get_active() ? 'on' : 'off';
$status3 = $checkbox3->get_active() ? 'on' : 'off';
$status_area->set_text("Status of checkbox1: $status1\n
Status of checkbox2: $status2\n
Status of checkbox3: $status3");
}
?>
|
More explanation at: http://www.kksou.com/php-gtk2/articles/change-the-font-and-color-of-checkbox-labels.php
Regards
/kksou |
|
| Back to top |
|
 |
stefan
Joined: 17 Apr 2006 Posts: 35 Location: Germany
|
Posted: Sat Mar 03, 2007 11:43 am Post subject: |
|
|
hey kksou,
thats exactly what i was looking for.
once more you gave me a lot of help.
thx a lot.
stefan |
|
| Back to top |
|
 |
|
|
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 vote in polls in this forum
|
|
 |