Sample Code 419: How to place a background image in GtkWindow - Part 4 - align bottom right - using GtkStyle?
Written by kksou   
Thursday, 24 January 2008
Problem

Suppose you want to have a single background image at the bottom right corner of a GtkWindow as shown below.

How to place a background image in GtkWindow - Part 4 - align bottom right - using GtkStyle?


Solution

Sample Code

Note: The following image file (sample6_1920_bottom_right.png) is required by the sample code below. Please save a copy of the image files and put them in the same directory where you store the sample code.

 

1   
2   
3   
4   
5   
6   
7   
8   
9   
10   
11   
12   
13   
14   
15   
16   
17   
18   
19   
20   
21   
<?php
$window = new GtkWindow();
$window->set_size_request(480, 240);
$window->connect_simple('destroy', array('Gtk','main_quit'));
$window->add($vbox = new GtkVBox());

// display title
$title = new GtkLabel("  Place a background image in GtkWindow\n".
"Part 4 - align bottom right - using GtkStyle");
$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);
$vbox->pack_start(new GtkLabel(), 0);
$vbox->pack_start(new GtkLabel("Try enlarge the window."));
$vbox->pack_start(new GtkLabel("There's only one image."));
$vbox->pack_start(new GtkLabel("But the background image ".
"stays at the same place!"));

// set background image
$pixbuf=GdkPixbuf::new_from_file("sample6_1920_bottom_right.png");
  • 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

The sample code above is exactly the same as that of the article How to place a background image in GtkWindow - Part 2 - tiled background image? (The only diffference is the background image.)

Pleaes refer to the article for explanations.


Note

Try changing the window size. Notice that the background image stays at the same old place and does not 'stick' to the bottom right corner of the window as shown below:

So this method is only suitable if you know that your user will not change the window size, or you always run your application in full-screen mode.

To make the background image stays at the bottom right corner of the window (no matter how the user changes the window size), please refer to the solution presented in How to place a background image in GtkWindow - Part 6 - align bottom right - GdkDrawable draw_pixbuf?


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.

 
< Prev   Next >

Copyright © 2006-2008. kksou.com. All Rights Reserved