PHP-GTK2 Newsletter
PHP-GTK2 Tips & Techniques
FREE Newsletter
by kksou
Sample Code 224: How to set the tab position for GtkTextView - Part 1 - in pixel unit? |
|
Written by kksou
|
|
Wednesday, 02 May 2007 |
|
Problem By default, GtkTreeView sets the tab at every eighth character as shown below:

You would like to change the tab position of a GtkTextView. In this Part 1, we will show how to set the tab position using pixel value (e.g. every 100 pixels) as shown below:

Solution
Sample Code 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| <?php $window = new GtkWindow(); $window->set_size_request(400, 240); $window->connect_simple('destroy', array('Gtk','main_quit')); $window->add($vbox = new GtkVBox());
// display title
$title = new GtkLabel("Set the Tab Position of GtkTextView\n". "Part 1 - by pixel unit"); $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); $title->set_justify(Gtk::JUSTIFY_CENTER); $alignment = new GtkAlignment(0.5, 0, 0, 0); $alignment->add($title); $vbox->pack_start($alignment, 0, 0); $vbox->pack_start(new GtkLabel(), 0, 0);
// Create a new buffer and a new view to show the buffer.
$buffer = new GtkTextBuffer(); $view = new GtkTextView(); $view->set_buffer($buffer); $view->modify_font(new PangoFontDescription("Courier New")); $view->set_wrap_mode(Gtk::WRAP_WORD);
$tabs = new PangoTabArray(0, true); // note 1
$tabs->set_tab(0, PANGO::TAB_LEFT, 100); // note 2
$tabs->set_tab(1, PANGO::TAB_LEFT, 200); // note 2
|
- 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.
Explanation
- Create a new PangoTabArray. Note that for the second parameter, set the value to
true to use pixel unit. Otherwise it will use pango unit.
- Set the tab positions. In this example, we set a tab for every 100 pixels.
- Set the tab on the treeview.
Related Links
User reviews There are no user reviews yet. Note: You have to be a registered member to leave a comment. Free registration here. |
|