GTK Introductory Learning: Fixed layout of layout containers

Source: Internet
Author: User
Tags gtk

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.