Tutorial

Inti Logo

« Text Widget
Timeout, IO and Idle Functions... »

Setting Widget Attributes

This section describes some of the more common methods used to operate on widgets. These can be used to set style, padding, size, etc. You will find many more methods declared in <inti/gtk/widget.h>.

After creating your widgets you will need to display them on screen. This is called showing and can be done with one of the following methods.

void show();

void show_all();

Any widget that isn't shown will not appear on the screen. If you want to show all the widgets in a container, it's easier to call Gtk::Widget::show_all() rather individually calling Gtk::Widget:show() for each widget.

Remember that you have to show the containers containing a widget, in addition to the widget itself, before it will appear onscreen.

The next method reverses the effects of Gtk::Widget::show() causing the widget to be hidden (invisible to the user).

void hide();

void hide_all();

For widgets that can be "activated" (buttons, menu items, etc.) this next method activates them. Activation is what happens when you press Enter on a widget during key navigation; clicking a button, selecting a menu item, etc. If the widget isn't activateable, the method returns false.

bool activate();

You can call Gtk::Widget::reparent() to move a widget from one Gtk::Container to another. This method handles the reference counting issues to avoid destroying the widget.

void reparent(Gtk::Widget& new_parent);

Call the next method  when you want a widget to have the keyboard focus. The widget must be a focusable widget, such as a Gtk::Entry; something like Gtk::Frame won't work. (More precisely, it must have the Gtk::CAN_FOCUS flag set.)

void grab_focus();

Widgets can be named, which allows you to refer to them from a gtkrc file. You can apply a style to widgets with a particular name in the gtkrc file. See the GTK+ documentation for gtkrc files (on the same page as the docs for GtkRcStyle). The following methods can be called to set and get a widget name.

void set_name(const String& name);

String get_name() const;

You can set the minimum size of a widget; that is, the widget's size request. The size request of a widget is the smallest size a widget can accept while still functioning well and drawing itself correctly. In some strange cases a widget may be allocated less than its requested size, and in many cases a widget may be allocated more space than it requested.

void set_size_request(int width, int height);

In most cases, Gtk::Window::set_default_size() is a better choice for toplevel windows than this method; setting the default size will still allow users to shrink the window. Setting the size request will force them to leave the window at least as large as the size request.

Note the inherent danger of setting any fixed size - themes, translations into other languages, different fonts, and user action can all change the appropriate size for a given widget. So, it's basically impossible to hard code a size that will always be correct.

If the size request in a given direction is -1 (unset), then the "natural" size request of the widget will be used instead. Passing 0,0 to this method means "as small as possible."

void get_size_request(int *width, int *height) const;

This method gets the size request that was explicitly set for the widget using Gtk::Widget::set_size_request(). A value of -1 for width or height indicates that that dimension has not been set explicitly and the natural requisition of the widget is being being used instead.

void set_style(Gtk::Style& style);

Sets the Gtk::Style for a widget (gtk_widget()->style). You probably don't want to use this function; it interacts badly with themes, because themes work by replacing the Gtk::Style. Instead, use Gtk::Widget::modify_style().

void modify_style(Gtk::RcStyle& style);

This method modifies style values on the widget. Modifications made using this technique take precedence over style values set via an RC file, however, they will be overridden if a style is explicitly set on the widget using Gtk::Widget_set_style().


« Text Widget Index
Top
Timeout, IO and Idle Functions... »