Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Gtk+/Gnome Application Development
Prev Home Next

Manually Affecting Layout

It's possible to manually override GTK+'s geometry management. This is a bad idea 95% of the time, because GTK+'s geometry is essentially the user's preferred geometry, determined by the theme, and resizing toplevel windows. If you find yourself wanting to do things manually, it's probably because you're using the wrong layout container, or you really should be writing a custom container widget.

You can force a size or position on a widget with the functions shown in Figure 19. However, it is rarely a good idea to use them. In particular, gtk_widget_set_usize() should not be used to set a toplevel window's default size. Usually you want to set window size because you've saved the application's state and you're restoring it, or because the user specified a window geometry on the command line. Unfortunately, if you use gtk_widget_set_usize() the user will be unable to shrink the window, and you'll get hate mail. Rather than force a size, you want to specify an initial size with gtk_window_set_default_size(), shown in Figure 20. gtk_widget_set_usize() is almost never a good idea for non-toplevel widgets either; most of the time, you can get better results using the proper layout widget.

gtk_widget_set_uposition() is only useful for toplevel windows; it borders on nonsensical for other widgets, and will most likely cause bad things to happen. It's primarily used to honor a --geometry command line argument.

All three of these functions can accept -1 for the x, y, width, or height argument. The functions ignore any -1 argument; this allows you to set only one of the two arguments, leaving the default value for the other.

#include <gtk/gtkwidget.h>

void gtk_widget_set_uposition(GtkWidget* widget, gint x, gint y);

void gtk_widget_set_usize(GtkWidget* widget, gint width, gint height);

Figure 19. Forcing Allocations

#include <gtk/gtkwindow.h>

void gtk_window_set_default_size(GtkWindow* window, gint width, gint height);

Figure 20. Default Window Size

Gtk+/Gnome Application Development
Prev Home Next

 
 
  Published under free license. Design by Interspire