The horizontal, vertical, and table layout containers we learned earlier, the controls are automatically adapted to changes in the size of the container, while the controls in the fixed layout container do not change (or are fixed).
fixed layout creation:
gtkwidget *gtk_fixed_new (void);
return value: Fixed layout container pointer
fixed layout container add control:
void gtk_fixed_put (
GtkFixed *fixed,
Gtkwidget *widget,
Gint x,
Gint y);
Fixed: container to hold controls
Widgets: Controls to add
X, Y: The starting coordinates of the position where the control is placed, such as:
Set the size (width and height) of the control:
void Gtk_widget_set_size_request (
Gtkwidget *widget,
Gint width,
Gint height);
Widgets: Controls that need to be set
Width: Wide
Height: High
To move a control's position in a fixed layout:
void Gtk_fixed_move (
Gtkfixed *fixed,
Gtkwidget *widget,
Gint x,
Gint y);
Fixed: Stationary layout container
Widgets: Controls that need to be moved
X, y: Moving position
The complete code is as follows:
#include <gtk/gtk.h>int main (int Argc,char *argv[]) {//1.GTK environment initialization gtk_ Init (&ARGC, &ARGV); 2. Create a window Gtkwidget *window = gtk_window_new (gtk_window_toplevel); 3. Create a stationary layout container fixed gtkwidget *fixed = Gtk_fixed_new (); Add fixed to Window Gtk_container_add (gtk_container (window), fixed); 4. Create a button Gtkwidget *button1 = Gtk_button_new_with_label ("button1"); Add button1 to Fixed container gtk_fixed_put (gtk_fixed (fixed), button1, 0,0); Gtkwidget *button2 = Gtk_button_new_with_label ("Button2"); Add button1 to Fixed container gtk_fixed_put (gtk_fixed (fixed), button2, 0, 0); 5. Move Button2 to (150,150) of position gtk_fixed_move (gtk_fixed (fixed), button2, 150, 150); 6. Set the size of the Button2 gtk_widget_set_size_request (button2,100, 50); 7. Display all Windows Gtk_widget_show_all (window); 8. Main Event loop Gtk_main (); return 0;}
Operation Result:
Source code Download: http://download.csdn.net/download/lianghe_work/8934195
Turn from:
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
GTK Introductory Learning: Fixed layout of layout containers