Re: How to center vbox inside full screen window



That did the trick, thanks!

-Christian

Arto Karppinen wrote:
Christian Smith wrote:
Hi All,

I have a very simple GTK program (in C) that creates a full screen window. Inside the full screen window I am placing a vbox with two elements inside: and image and a label.

For the life of me I cannot figure out how to get the contents of the vbox to be packed together. I.e. I want the image + label touching each other and centered on the screen. Currently the height of the vbox seems to fill the height of the screen with the image and label distributed inside (and not touching).

Any help is appreciated!

You need to put you VBox inside GtkAlignment

gtk_alignment_new(gfloat xalign,
                  gfloat yalign,
                  gfloat xscale,
                  gfloat yscale);

Set alignment to center (0,5),
And disable scaling of vbox (0).

Like this:

GtkWidget *align = gtk_alignment_new(0.5, 0.5, 0, 0);
gtk_container_add(GTK_CONTAINER(align), vbox);

After which alignment widget will use the "extra" space in the window, and vbox uses only what it needs. The important part to understand is that the entire space of the window must always be allocated to some widget in Gtk. So if you just put a VBox inside the window, it must fill the whole window.






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