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).


To create a fixed layout:
Gtkwidget *gtk_fixed_new (void);
Return value: Fixed layout container pointer


To add a control to a fixed layout container:
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[]) {gtk_init (&ARGC, &ARGV);//Initialize Gtkwidget *windo W = gtk_window_new (gtk_window_toplevel);  Create window Gtkwidget *fixed = gtk_fixed_new (); Create a fixed container gtk_container_add (gtk_container (window), fixed); Fixed put into window gtkwidget *button1 = Gtk_button_new_with_label ("^_^");  Create button Gtk_fixed_put (gtk_fixed (fixed), button1, 0, 0); The button is added to the fixed layout gtkwidget *button2 = Gtk_button_new_with_label ("@[email protected]");  Create button Gtk_fixed_put (gtk_fixed (fixed), button2, 0, 0); The button is added to the fixed layout gtk_fixed_move (gtk_fixed (fixed), button2, 150, 150); The position of the mobile control gtk_widget_set_size_request (button2, 100, 50); Sets the size of the control gtk_widget_show_all (window);  Show all Controls Gtk_main ();  Enter event loop  

The program runs as follows:




Source code download please click here.



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.