Sample Code 200: How to set GtkTextView to look like GtkLabel?
Written by kksou
|Last Update: Friday, 16 March 2007|
A standard GtkTextView has a white background as shown below:
You would like to set the background color of the GtkTextView to the default gray color of the window so that the GtkTextView looks like a GtkLabel as shown below:
| 1 |
$window = &new GtkWindow();
$window->connect_simple('destroy', array( 'Gtk', 'main_quit'));
$window->add($vbox = new GtkVBox());
// display title
$title = new GtkLabel("Set bg color of textview to default bg color");
$title->modify_font(new PangoFontDescription("Times New Roman Italic 10"));
$alignment = new GtkAlignment(0.5, 0, 0, 0);
$vbox->pack_start($alignment, 0, 0);
$vbox->pack_start(new GtkLabel(), 0, 0);
$window->realize(); // note 1
$org_bg = $window->get_style()->bg[Gtk::STATE_NORMAL]; // note 2
// setup textview and textbuffer
$buffer = new GtkTextBuffer();
$view = new GtkTextView();
$view->modify_font(new PangoFontDescription("Arial 12"));
$scrolled_win = new GtkScrolledWindow();
$scrolled_win->set_policy( Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
- Note that this is only 70% of the sample code. You have to be a registered member to see the entire sample code. Please login or register.
- Registration is free and immediate.
- Have some doubt about the registration? Please read this forum article.
- Remember to realize the window before making a copy of the original background color. Try commenting this line out and you will find that you won't get the original color.
- Make a copy of the original background color.
- Set the GtkTextView to the default gray, making it look like a GtkLabel.
Note that we make use of exactly the same technique as we have used in How to set the background to original default color?