gtkmm: Gtk::Builder Class Reference

gtkmm 4.14.0

Public Member Functions | Static Public Member Functions | Protected Member Functions | Related Symbols | List of all members
Gtk::Builder Class Reference

Build an interface from an XML UI definition description. More...

`#include <gtkmm/builder.h>`

Inheritance diagram for Gtk::Builder:
[legend]

## Public Member Functions
| Builder (Builder &&src) noexcept
Builder & | operator= (Builder &&src) noexcept
| ~Builder () noexcept override
GtkBuilder * | gobj ()
| Provides access to the underlying C GObject.
const GtkBuilder * | gobj () const
| Provides access to the underlying C GObject.
GtkBuilder * | gobj_copy ()
| Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.
bool | add_from_file (const std::string &filename)
| Parses a file containing a GtkBuilder UI definition, and merges it with the current contents of the builder.
bool | add_from_file (const std::string &filename, const char *object_id)
| Parses a file containing a GtkBuilder UI definition, building only the requested object, and merges it with the current contents of the builder.
bool | add_from_file (const std::string &filename, const Glib::ustring &object_id)
| Parses a file containing a GtkBuilder UI definition, building only the requested object, and merges it with the current contents of the builder.
bool | add_from_file (const std::string &filename, const std::vector< Glib::ustring > &object_ids)
| Parses a file containing a UI definition building only the requested objects and merges them with the current contents of builder.
bool | add_from_resource (const std::string &resource_path)
| Parses a resource file containing a GtkBuilder UI definition, and merges it with the current contents of the builder.
bool | add_from_resource (const std::string &resource_path, const char *object_id)
| Parses a resource file containing a GtkBuilder UI definition, building only the requested object, and merges it with the current contents of the builder.
bool | add_from_resource (const std::string &resource_path, const Glib::ustring &object_id)
| Parses a resource file containing a GtkBuilder UI definition, building only the requested object, and merges it with the current contents of the builder.
bool | add_from_resource (const std::string &resource_path, const std::vector< Glib::ustring > &object_ids)
| Parses a resource file containing a UI definition, building only the requested objects and merges them with the current contents of builder.
bool | add_from_string (const Glib::ustring &buffer)
| Parses a string containing a GtkBuilder UI definition and merges it with the current contents of the builder.
bool | add_from_string (const Glib::ustring &buffer, const char *object_id)
| Parses a string containing a GtkBuilder UI definition, building only the requested object, and merges it with the current contents of the builder.
bool | add_from_string (const Glib::ustring &buffer, const Glib::ustring &object_id)
| Parses a string containing a GtkBuilder UI definition, building only the requested object, and merges it with the current contents of the builder.
bool | add_from_string (const Glib::ustring &buffer, const std::vector< Glib::ustring > &object_ids)
| Parses a string containing a GtkBuilder UI definition, building only the requested objects, and merges it with the current contents of the builder.
bool | add_from_string (const char *buffer, gssize length)
| Parses a string containing a GtkBuilder UI definition and merges it with the current contents of the builder.
void | expose_object (const Glib::ustring & name, const Glib::RefPtr< Glib::Object > &object)
| Add object to the builder object pool so it can be referenced just like any other object built by builder.
void | expose_widget (const Glib::ustring & name, Widget &widget)
| Add widget to the builder object pool so it can be referenced just like any other object built by builder.
Glib::RefPtr< Glib::Object > | get_object (const Glib::ustring & name)
| Gets the object named name.
Glib::RefPtr< const Glib::Object > | get_object (const Glib::ustring & name) const
| Gets the object named name.
template<class T_Object >
Glib::RefPtr< T_Object > | get_object (const Glib::ustring & name)
| Gets the object named name, cast to a specific derived type.
template<class T_Object >
Glib::RefPtr< const T_Object > | get_object (const Glib::ustring & name) const
| See the non-const version.
template<class T_Widget >
T_Widget * | get_widget (const Glib::ustring & name)
| Gets a widget from the Builder file.
template<class T_Widget >
const T_Widget * | get_widget (const Glib::ustring & name) const
| See the non-const version.
std::vector< Glib::RefPtr< Glib::Object > > | get_objects ()
| Gets all objects that have been constructed by the Gtk::Builder.
std::vector< Glib::RefPtr< const Glib::Object > > | get_objects () const
| Gets all objects that have been constructed by the Gtk::Builder.
void | set_translation_domain (const Glib::ustring &domain)
| Sets the translation domain of builder.
Glib::ustring | get_translation_domain () const
| Gets the translation domain of builder.
Glib::PropertyProxy< Glib::ustring > | property_translation_domain ()
| The translation domain used when translating property values that have been marked as translatable.
Glib::PropertyProxy_ReadOnly< Glib::ustring > | property_translation_domain () const
| The translation domain used when translating property values that have been marked as translatable.

## Static Public Member Functions
static GType | get_type ()
| Get the GType for this class, for use with the underlying GObject type system.
static Glib::RefPtr< Builder > | create ()
| Creates a new builder object.
static Glib::RefPtr< Builder > | create_from_file (const std::string &filename)
| Parses a file containing a GtkBuilder UI definition.
static Glib::RefPtr< Builder > | create_from_file (const std::string &filename, const Glib::ustring &object_id)
| Parses a file containing a GtkBuilder UI definition, building only the requested object.
static Glib::RefPtr< Builder > | create_from_file (const std::string &filename, const char *object_id)
| Parses a file containing a GtkBuilder UI definition, building only the requested object.
static Glib::RefPtr< Builder > | create_from_file (const std::string &filename, const std::vector< Glib::ustring > &object_ids)
| Parses a file containing a GtkBuilder UI definition, building only the requested objects.
static Glib::RefPtr< Builder > | create_from_resource (const std::string &resource_path)
| Parses a resource file containing a GtkBuilder UI definition.
static Glib::RefPtr< Builder > | create_from_resource (const std::string &resource_path, const Glib::ustring &object_id)
| Parses a resource file containing a GtkBuilder UI definition, building only the requested object.
static Glib::RefPtr< Builder > | create_from_resource (const std::string &resource_path, const char *object_id)
| Parses a resource file containing a GtkBuilder UI definition, building only the requested object.
static Glib::RefPtr< Builder > | create_from_resource (const std::string &resource_path, const std::vector< Glib::ustring > &object_ids)
| Parses a resource file containing a GtkBuilder UI definition, building only the requested objects.
static Glib::RefPtr< Builder > | create_from_string (const Glib::ustring &buffer)
| Parses a string containing a GtkBuilder UI definition.
static Glib::RefPtr< Builder > | create_from_string (const Glib::ustring &buffer, const char *object_id)
| Parses a string containing a GtkBuilder UI definition building only the requested object.
static Glib::RefPtr< Builder > | create_from_string (const Glib::ustring &buffer, const Glib::ustring &object_id)
| Parses a string containing a GtkBuilder UI definition building only the requested object.
static Glib::RefPtr< Builder > | create_from_string (const Glib::ustring &buffer, const std::vector< Glib::ustring > &object_ids)
| Parses a string containing a GtkBuilder UI definition building only the requested objects.
template<typename T_Widget , typename... Args>
static T_Widget * | get_widget_derived (const Glib::RefPtr< Gtk::Builder > &builder, const Glib::ustring & name, Args &&... args)
| Gets a widget whose details are specified in the GtkBuilder file, but which is implemented by your own derived class.
template<typename T_Widget , typename... Args>
static const T_Widget * | get_widget_derived (const Glib::RefPtr< const Gtk::Builder > &builder, const Glib::ustring & name, Args &&... args)
| See the non-const version.

## Protected Member Functions
| Builder ()
Gtk::Widget * | get_widget_checked (const Glib::ustring & name, GType type)
GtkWidget * | get_cwidget (const Glib::ustring & name)

## Related Symbols
(Note that these are not member symbols.)
Glib::RefPtr< Gtk::Builder > | wrap (GtkBuilder *object, bool take_copy=false)
| A Glib::wrap() method for this object.

## Detailed Description

Build an interface from an XML UI definition description.

This object represents an ‘instantiation’ of an UI definition description. When one of these objects is created, the XML file is read, and the user interface is created. The Gtk::Builder object then provides an interface for accessing the widgets in the user interface by the names assigned to them inside the UI description.

A Gtk::Builder holds a reference to all objects that it has constructed and drops these references when it is deleted. This deletion can cause the destruction of non-widget objects or widgets which are not contained in a toplevel window. For toplevel windows constructed by a builder, it is the responsibility of the user to get them with get_widget() or get_widget_derived() and delete them to get rid of them and all the widgets they contain.

The methods get_widget() and get_widget_derived() can be used to access the widgets in the interface by the names assigned to them inside the UI description. Toplevel windows returned by these methods will stay around until the user explicitly deletes them. Other widgets will either be part of a larger hierarchy constructed by the builder (in which case you should not have to worry about their lifecycle), or without a parent, in which case they have to be added to some container before the builder is deleted to make use of them.

Non-widget objects need to be fetched with get_object() or get_objects() to keep them beyond the lifespan of the builder.

Gtk::Builder and Glib::Property
  A derived widget that contains Glib::Property members must be registered with its own name in the GType system. It must be registered before any of the create_from_*() or add_from_*() methods are called, meaning that you may have to create an instance of your derived widget just to have its class registered. There is no reasonably easy way to combine Gtk::Builder with non-widget objects containing Glib::Property members. Combining it with widgets containing Glib::Property members requires glibmm 2.62 or newer. See also get_widget_derived() and Glib::Property.

Since gtkmm 2.12

## Constructor & Destructor Documentation

## ◆ Builder() [1/2]

Gtk::Builder::Builder | ( | Builder && | src | ) |
| noexcept

## ◆ ~Builder()

Gtk::Builder::~Builder | ( |  | ) |
| overridenoexcept

## ◆ Builder() [2/2]

Gtk::Builder::Builder | ( |  | ) |
| protected

## Member Function Documentation

## ◆ add_from_file() [1/4]

bool Gtk::Builder::add_from_file | ( | const std::string & | filename | ) |

Parses a file containing a GtkBuilder UI definition, and merges it with the current contents of the builder.

Parameters

  filename | The file to parse.

Returns
  true on success or false if an error occurred.

Exceptions

  BuilderError,Glib::MarkupError,Glib::MarkupError |

Since gtkmm 2.14

## ◆ add_from_file() [2/4]

bool Gtk::Builder::add_from_file | ( | const std::string & | filename,
|  | const char * | object_id )

Parses a file containing a GtkBuilder UI definition, building only the requested object, and merges it with the current contents of the builder.

If you are adding an object that depends on an object that is not its child (for instance a GtkTreeView that depends on its GtkTreeModel), you have to explicitely list all of them.

Parameters

  filename | The file to parse.
  object_id | The object to build.

Returns
  true on success or false if an error occurred.

Exceptions

  BuilderError,Glib::MarkupError,Glib::MarkupError |

Since gtkmm 2.16

## ◆ add_from_file() [3/4]

bool Gtk::Builder::add_from_file | ( | const std::string & | filename,
|  | const Glib::ustring & | object_id )

Parses a file containing a GtkBuilder UI definition, building only the requested object, and merges it with the current contents of the builder.

If you are adding an object that depends on an object that is not its child (for instance a GtkTreeView that depends on its GtkTreeModel), you have to explicitely list all of them.

Parameters

  filename | The file to parse.
  object_id | The object to build.

Returns
  true on success or false if an error occurred.

Exceptions

  BuilderError,Glib::MarkupError,Glib::MarkupError |

Since gtkmm 2.14

## ◆ add_from_file() [4/4]

bool Gtk::Builder::add_from_file | ( | const std::string & | filename,
|  | const std::vector< Glib::ustring > & | object_ids )

Parses a file containing a UI definition building only the requested objects and merges them with the current contents of builder.

Upon errors, 0 will be returned and error will be assigned a `GError` from the GTK_BUILDER_ERROR, G_MARKUP_ERROR or G_FILE_ERROR domain.

If you are adding an object that depends on an object that is not its child (for instance a `Gtk::TreeView` that depends on its `Gtk::TreeModel`), you have to explicitly list all of them in object_ids.

Parameters

  filename | The name of the file to parse.
  object_ids | Nul-terminated array of objects to build.

Returns
  `true` on success, `false` if an error occurred.

Exceptions

  Glib::Error |

## ◆ add_from_resource() [1/4]

bool Gtk::Builder::add_from_resource | ( | const std::string & | resource_path | ) |

Parses a resource file containing a GtkBuilder UI definition, and merges it with the current contents of the builder.

Parameters

  resource_path | The path of the resource file to parse.

Returns
  true on success or false if an error occurred.

Exceptions

  BuilderError,Glib::MarkupError,Gio::ResourceError |

Since gtkmm 3.6

## ◆ add_from_resource() [2/4]

bool Gtk::Builder::add_from_resource | ( | const std::string & | resource_path,
|  | const char * | object_id )

Parses a resource file containing a GtkBuilder UI definition, building only the requested object, and merges it with the current contents of the builder.

If you are adding an object that depends on an object that is not its child (for instance a GtkTreeView that depends on its GtkTreeModel), you have to explicitely list all of them.

Parameters

  resource_path | The path of the resource file to parse.
  object_id | The object to build.

Returns
  true on success or false if an error occurred.

Exceptions

  BuilderError,Glib::MarkupError,Gio::ResourceError |

Since gtkmm 3.6

## ◆ add_from_resource() [3/4]

bool Gtk::Builder::add_from_resource | ( | const std::string & | resource_path,
|  | const Glib::ustring & | object_id )

Parses a resource file containing a GtkBuilder UI definition, building only the requested object, and merges it with the current contents of the builder.

If you are adding an object that depends on an object that is not its child (for instance a GtkTreeView that depends on its GtkTreeModel), you have to explicitely list all of them.

Parameters

  resource_path | The path of the resource file to parse.
  object_id | The object to build.

Returns
  true on success or false if an error occurred.

Exceptions

  BuilderError,Glib::MarkupError,Gio::ResourceError |

Since gtkmm 3.6

## ◆ add_from_resource() [4/4]

bool Gtk::Builder::add_from_resource | ( | const std::string & | resource_path,
|  | const std::vector< Glib::ustring > & | object_ids )

Parses a resource file containing a UI definition, building only the requested objects and merges them with the current contents of builder.

Upon errors, 0 will be returned and error will be assigned a `GError` from the GTK_BUILDER_ERROR, G_MARKUP_ERROR or G_RESOURCE_ERROR domain.

If you are adding an object that depends on an object that is not its child (for instance a `Gtk::TreeView` that depends on its `Gtk::TreeModel`), you have to explicitly list all of them in object_ids.

Parameters

  resource_path | The path of the resource file to parse.
  object_ids | Nul-terminated array of objects to build.

Returns
  `true` on success, `false` if an error occurred.

Exceptions

  Glib::Error |

## ◆ add_from_string() [1/5]

bool Gtk::Builder::add_from_string | ( | const char * | buffer,
|  | gssize | length )

Parses a string containing a GtkBuilder UI definition and merges it with the current contents of the builder.

Parameters

  buffer | The string to parse.
  length | The length of buffer (may be -1 if buffer is nul-terminated).

Returns
  true on success or false if an error occurred.

Exceptions

  BuilderError,Glib::MarkupError |

Since gtkmm 2.12

## ◆ add_from_string() [2/5]

bool Gtk::Builder::add_from_string | ( | const Glib::ustring & | buffer | ) |

Parses a string containing a GtkBuilder UI definition and merges it with the current contents of the builder.

Parameters

  buffer | The string to parse.

Returns
  true on success or false if an error occurred.

Exceptions

  BuilderError,Glib::MarkupError |

Since gtkmm 2.12

## ◆ add_from_string() [3/5]

bool Gtk::Builder::add_from_string | ( | const Glib::ustring & | buffer,
|  | const char * | object_id )

Parses a string containing a GtkBuilder UI definition, building only the requested object, and merges it with the current contents of the builder.

Parameters

  buffer | The string to parse.
  object_id | The object to build.

Returns
  true on success or false if an error occurred.

Exceptions

  BuilderError,Glib::MarkupError |

Since gtkmm 2.16

## ◆ add_from_string() [4/5]

bool Gtk::Builder::add_from_string | ( | const Glib::ustring & | buffer,
|  | const Glib::ustring & | object_id )

Parses a string containing a GtkBuilder UI definition, building only the requested object, and merges it with the current contents of the builder.

Parameters

  buffer | The string to parse.
  object_id | The object to build.

Returns
  true on success or false if an error occurred.

Exceptions

  BuilderError,Glib::MarkupError |

Since gtkmm 2.14

## ◆ add_from_string() [5/5]

bool Gtk::Builder::add_from_string | ( | const Glib::ustring & | buffer,
|  | const std::vector< Glib::ustring > & | object_ids )

Parses a string containing a GtkBuilder UI definition, building only the requested objects, and merges it with the current contents of the builder.

Parameters

  buffer | The string to parse.
  object_ids | The objects to build.

Returns
  true on success or false if an error occurred.

Exceptions

  BuilderError,Glib::MarkupError |

Since gtkmm 2.14

## ◆ create()

static Glib::RefPtr< Builder > Gtk::Builder::create | ( |  | ) |
| static

Creates a new builder object.

## ◆ create_from_file() [1/4]

static Glib::RefPtr< Builder > Gtk::Builder::create_from_file | ( | const std::string & | filename | ) |
| static

Parses a file containing a GtkBuilder UI definition.

Parameters

  filename | the name of the file to parse.

Returns
  A new Builder object, or a null pointer if an error occurred.

Exceptions

  BuilderError,Glib::MarkupError,Glib::FileError |

Since gtkmm 2.12

## ◆ create_from_file() [2/4]

static Glib::RefPtr< Builder > Gtk::Builder::create_from_file | ( | const std::string & | filename,
|  | const char * | object_id )
| static

Parses a file containing a GtkBuilder UI definition, building only the requested object.

If you are adding an object that depends on an object that is not its child (for instance a GtkTreeView that depends on its GtkTreeModel), you have to explicitely list all of them.

Parameters

  filename | the name of the file to parse.
  object_id | The object to build.

Returns
  A new Builder object, or a null pointer if an error occurred.

Exceptions

  BuilderError,Glib::MarkupError,Glib::FileError |

Since gtkmm 2.16

## ◆ create_from_file() [3/4]

static Glib::RefPtr< Builder > Gtk::Builder::create_from_file | ( | const std::string & | filename,
|  | const Glib::ustring & | object_id )
| static

Parses a file containing a GtkBuilder UI definition, building only the requested object.

If you are adding an object that depends on an object that is not its child (for instance a GtkTreeView that depends on its GtkTreeModel), you have to explicitely list all of them.

Parameters

  filename | the name of the file to parse.
  object_id | The object to build.

Returns
  A new Builder object, or a null pointer if an error occurred.

Exceptions

  BuilderError,Glib::MarkupError,Glib::FileError |

Since gtkmm 2.14

## ◆ create_from_file() [4/4]

static Glib::RefPtr< Builder > Gtk::Builder::create_from_file | ( | const std::string & | filename,
|  | const std::vector< Glib::ustring > & | object_ids )
| static

Parses a file containing a GtkBuilder UI definition, building only the requested objects.

If you are adding an object that depends on an object that is not its child (for instance a GtkTreeView that depends on its GtkTreeModel), you have to explicitely list all of them.

Parameters

  filename | the name of the file to parse.
  object_ids | The objects to build.

Returns
  A new Builder object, or a null pointer if an error occurred.

Exceptions

  BuilderError,Glib::MarkupError,Glib::FileError |

Since gtkmm 2.14

## ◆ create_from_resource() [1/4]

static Glib::RefPtr< Builder > Gtk::Builder::create_from_resource | ( | const std::string & | resource_path | ) |
| static

Parses a resource file containing a GtkBuilder UI definition.

Parameters

  resource_path | The path of the resource file to parse.

Returns
  A new Builder object, or a null pointer if an error occurred.

Exceptions

  BuilderError,Glib::MarkupError,Gio::ResourceError |

Since gtkmm 3.6

## ◆ create_from_resource() [2/4]

static Glib::RefPtr< Builder > Gtk::Builder::create_from_resource | ( | const std::string & | resource_path,
|  | const char * | object_id )
| static

Parses a resource file containing a GtkBuilder UI definition, building only the requested object.

If you are adding an object that depends on an object that is not its child (for instance a GtkTreeView that depends on its GtkTreeModel), you have to explicitely list all of them.

Parameters

  resource_path | The path of the resource file to parse.
  object_id | The object to build.

Returns
  A new Builder object, or a null pointer if an error occurred.

Exceptions

  BuilderError,Glib::MarkupError,Gio::ResourceError |

Since gtkmm 3.6

## ◆ create_from_resource() [3/4]

static Glib::RefPtr< Builder > Gtk::Builder::create_from_resource | ( | const std::string & | resource_path,
|  | const Glib::ustring & | object_id )
| static

Parses a resource file containing a GtkBuilder UI definition, building only the requested object.

If you are adding an object that depends on an object that is not its child (for instance a GtkTreeView that depends on its GtkTreeModel), you have to explicitely list all of them.

Parameters

  resource_path | The path of the resource file to parse.
  object_id | The object to build.

Returns
  A new Builder object, or a null pointer if an error occurred.

Exceptions

  BuilderError,Glib::MarkupError,Gio::ResourceError |

Since gtkmm 3.6

## ◆ create_from_resource() [4/4]

static Glib::RefPtr< Builder > Gtk::Builder::create_from_resource | ( | const std::string & | resource_path,
|  | const std::vector< Glib::ustring > & | object_ids )
| static

Parses a resource file containing a GtkBuilder UI definition, building only the requested objects.

If you are adding an object that depends on an object that is not its child (for instance a GtkTreeView that depends on its GtkTreeModel), you have to explicitely list all of them.

Parameters

  resource_path | The path of the resource file to parse.
  object_ids | The objects to build.

Returns
  A new Builder object, or a null pointer if an error occurred.

Exceptions

  BuilderError,Glib::MarkupError,Gio::ResourceError |

Since gtkmm 3.6

## ◆ create_from_string() [1/4]

static Glib::RefPtr< Builder > Gtk::Builder::create_from_string | ( | const Glib::ustring & | buffer | ) |
| static

Parses a string containing a GtkBuilder UI definition.

Parameters

  buffer | the string to parse

Returns
  A new Builder object, or a null pointer if an error occurred.

Exceptions

  BuilderError,Glib::MarkupError |

Since gtkmm 2.12

## ◆ create_from_string() [2/4]

static Glib::RefPtr< Builder > Gtk::Builder::create_from_string | ( | const Glib::ustring & | buffer,
|  | const char * | object_id )
| static

Parses a string containing a GtkBuilder UI definition building only the requested object.

Parameters

  buffer | The string to parse.
  object_id | The object to build.

Returns
  A new Builder object, or a null pointer if an error occurred.

Exceptions

  BuilderError,Glib::MarkupError |

Since gtkmm 2.16

## ◆ create_from_string() [3/4]

static Glib::RefPtr< Builder > Gtk::Builder::create_from_string | ( | const Glib::ustring & | buffer,
|  | const Glib::ustring & | object_id )
| static

Parses a string containing a GtkBuilder UI definition building only the requested object.

Parameters

  buffer | The string to parse.
  object_id | The object to build.

Returns
  A new Builder object, or a null pointer if an error occurred.

Exceptions

  BuilderError,Glib::MarkupError |

Since gtkmm 2.14

## ◆ create_from_string() [4/4]

static Glib::RefPtr< Builder > Gtk::Builder::create_from_string | ( | const Glib::ustring & | buffer,
|  | const std::vector< Glib::ustring > & | object_ids )
| static

Parses a string containing a GtkBuilder UI definition building only the requested objects.

If you are adding an object that depends on an object that is not its child (for instance a GtkTreeView that depends on its GtkTreeModel), you have to explicitely list all of them.

Parameters

  buffer | the string to parse
  object_ids | The objects to build.

Returns
  A new Builder object, or a null pointer if an error occurred.

Exceptions

  BuilderError,Glib::MarkupError |

Since gtkmm 2.14

## ◆ expose_object()

void Gtk::Builder::expose_object | ( | const Glib::ustring & | name,
|  | const Glib::RefPtr< Glib::Object > & | object )

Add object to the builder object pool so it can be referenced just like any other object built by builder.

Only a single object may be added using name. However, it is not an error to expose the same object under multiple names. `get_object()` may be used to determine if an object has already been added with name.

Parameters

  name | The name of the object exposed to the builder.
  object | The object to expose.

## ◆ expose_widget()

void Gtk::Builder::expose_widget | ( | const Glib::ustring & | name,
|  | Widget & | widget )

Add widget to the builder object pool so it can be referenced just like any other object built by builder.

Since gtkmm 3.12

Parameters

  name | The name of the widget exposed to the builder.
  widget | The widget to expose.

## ◆ get_cwidget()

GtkWidget * Gtk::Builder::get_cwidget | ( | const Glib::ustring & | name | ) |
| protected

## ◆ get_object() [1/4]

Glib::RefPtr< Glib::Object > Gtk::Builder::get_object | ( | const Glib::ustring & | name | ) |

Gets the object named name.

Since gtkmm 2.12

Parameters

  name | Name of object to get.

Returns
  The object named name or `nullptr` if it could not be found in the object tree.

## ◆ get_object() [2/4]

template <class T_Object >

Glib::RefPtr< T_Object > Gtk::Builder::get_object | ( | const Glib::ustring & | name | ) |
| inline

Gets the object named name, cast to a specific derived type.

For instance:

auto adjustment = refBuilder->get_object<Gtk::Adjustment>("adjustment_id");
adjustment->set_value(42);
Gtk::Adjustment
A class representing an adjustable bounded value.
Definition adjustment.h:60
Gtk::Adjustment::set_value
void set_value(double value)
Sets the current value of the Adjustment.

Since gtkmm 3.96

Parameters

  name | Name of object to get.

Returns
  The object named name or `nullptr` if it could not be found in the object tree or could not be cast to the specified type.

## ◆ get_object() [3/4]

Glib::RefPtr< const Glib::Object > Gtk::Builder::get_object | ( | const Glib::ustring & | name | ) | const

Gets the object named name.

Since gtkmm 3.8

Parameters

  name | Name of object to get.

Returns
  The object named name or `nullptr` if it could not be found in the object tree.

## ◆ get_object() [4/4]

template <class T_Object >

Glib::RefPtr< const T_Object > Gtk::Builder::get_object | ( | const Glib::ustring & | name | ) | const
| inline

See the non-const version.

Since gtkmm 3.96

## ◆ get_objects() [1/2]

std::vector< Glib::RefPtr< Glib::Object > > Gtk::Builder::get_objects | ( |  | ) |

Gets all objects that have been constructed by the Gtk::Builder.

Since gtkmm 3.8

Returns
  A vector containing all the objects constructed by the Gtk::Builder instance.

## ◆ get_objects() [2/2]

std::vector< Glib::RefPtr< const Glib::Object > > Gtk::Builder::get_objects | ( |  | ) | const

Gets all objects that have been constructed by the Gtk::Builder.

Since gtkmm 3.8

Returns
  A vector containing all the objects constructed by the Gtk::Builder instance.

## ◆ get_translation_domain()

Glib::ustring Gtk::Builder::get_translation_domain | ( |  | ) | const

Gets the translation domain of builder.

Returns
  The translation domain.

## ◆ get_type()

static GType Gtk::Builder::get_type | ( |  | ) |
| static

Get the GType for this class, for use with the underlying GObject type system.

## ◆ get_widget() [1/2]

template <class T_Widget >

T_Widget * Gtk::Builder::get_widget | ( | const Glib::ustring & | name | ) |
| inline

Gets a widget from the Builder file.

For instance:

auto pGrid = refBuilder->get_widget<Gtk::Grid>("mygrid");
Gtk::Grid
A container which arranges its child widgets in rows and columns.
Definition grid.h:66

This method prints a warning message to the console if the widget doesn't exist or has the wrong type, so you don't need to check that manually.

Note that you are responsible for deleting top-level widgets (windows and dialogs) instantiated by the Builder object. Other widgets are instantiated as managed so they will be deleted automatically if you add them to a container widget.

Parameters

  name | The name of the widget.

Returns
  A pointer to the widget, or `nullptr` on failure.

Since gtkmm 3.96

## ◆ get_widget() [2/2]

template <class T_Widget >

const T_Widget * Gtk::Builder::get_widget | ( | const Glib::ustring & | name | ) | const
| inline

See the non-const version.

Since gtkmm 3.96

## ◆ get_widget_checked()

Gtk::Widget * Gtk::Builder::get_widget_checked | ( | const Glib::ustring & | name,
|  | GType | type )
| protected

## ◆ get_widget_derived() [1/2]

template <typename T_Widget , typename... Args>

static const T_Widget * Gtk::Builder::get_widget_derived | ( | const Glib::RefPtr< const Gtk::Builder > & | builder,
|  | const Glib::ustring & | name,
|  | Args &&... | args )
| inlinestatic

See the non-const version.

Since gtkmm 3.96

## ◆ get_widget_derived() [2/2]

template <typename T_Widget , typename... Args>

static T_Widget * Gtk::Builder::get_widget_derived | ( | const Glib::RefPtr< Gtk::Builder > & | builder,
|  | const Glib::ustring & | name,
|  | Args &&... | args )
| inlinestatic

Gets a widget whose details are specified in the GtkBuilder file, but which is implemented by your own derived class.

Your class must have a constructor like so:

MyDerivedDialog::MyDerivedDialog(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& refBuilder)
: Gtk::Dialog(cobject) //Calls the base class constructor
Gtk::Dialog
Create popup windows.
Definition dialog.h:189
Gtk
Definition accelerator.h:28

or, with additional parameters, for example:

MyDerivedDialog::MyDerivedDialog(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& refBuilder,
const Glib::ustring& msg, bool warning)
: Gtk::Dialog(cobject) //Calls the base class constructor

For instance:

auto pDialog1 = Gtk::Builder::get_widget_derived<MyDerivedDialog>(refBuilder, "mydialog1");
auto pDialog2 = Gtk::Builder::get_widget_derived<MyDerivedDialog>(refBuilder, "mydialog2", "A storm is imminent!", true);

Note
  If get_widget_derived() is called more than once for the same widget (the same name), only the first call will call the widget's constructor. The following calls will return a pointer to the widget instance that was constructed by the first call.

Gtk::Builder and Glib::Property
  If the widget contains Glib::Property members, your constructor must call the Glib::ObjectBase constructor with a new GType name:
  MyDerivedDialog::MyDerivedDialog(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& refBuilder)
  : Glib::ObjectBase("MyDialog"), // The GType name will be gtkmm__CustomObject_MyDialog
  Gtk::Dialog(cobject) // Calls the base class constructor
  m_my_property(*this, "my-property")
  Glib

Parameters

  builder | The Gtk::Builder from which to get the widget.
  name | The name of the widget.
  args | Additional arguments to pass to the constructor of the derived class.

Returns
  A pointer to the widget, or `nullptr` on failure.

Since gtkmm 3.96

## ◆ gobj() [1/2]

GtkBuilder * Gtk::Builder::gobj | ( |  | ) |
| inline

Provides access to the underlying C GObject.

## ◆ gobj() [2/2]

const GtkBuilder * Gtk::Builder::gobj | ( |  | ) | const
| inline

Provides access to the underlying C GObject.

## ◆ gobj_copy()

GtkBuilder * Gtk::Builder::gobj_copy | ( |  | ) |

Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.

## ◆ operator=()

Builder & Gtk::Builder::operator= | ( | Builder && | src | ) |
| noexcept

## ◆ property_translation_domain() [1/2]

Glib::PropertyProxy< Glib::ustring > Gtk::Builder::property_translation_domain | ( |  | ) |

The translation domain used when translating property values that have been marked as translatable.

If the translation domain is `nullptr`, `Gtk::Builder` uses gettext(), otherwise Glib::dgettext().

Default value: ""

Returns
  A PropertyProxy that allows you to get or set the value of the property, or receive notification when the value of the property changes.

## ◆ property_translation_domain() [2/2]

Glib::PropertyProxy_ReadOnly< Glib::ustring > Gtk::Builder::property_translation_domain | ( |  | ) | const

The translation domain used when translating property values that have been marked as translatable.

If the translation domain is `nullptr`, `Gtk::Builder` uses gettext(), otherwise Glib::dgettext().

Default value: ""

Returns
  A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

## ◆ set_translation_domain()

void Gtk::Builder::set_translation_domain | ( | const Glib::ustring & | domain | ) |

Sets the translation domain of builder.

Parameters

  domain | The translation domain.

## Friends And Related Symbol Documentation

## ◆ wrap()

Glib::RefPtr< Gtk::Builder > wrap | ( | GtkBuilder * | object,
|  | bool | take_copy = false )
| related

A Glib::wrap() method for this object.

Parameters

  object | The C instance.
  take_copy | False if the result should take ownership of the C instance. True if it should take a new copy or ref.

Returns
  A C++ instance that wraps this C instance.