Anpassade komponenter
By deriving directly from Gtk::Widget you can do all the drawing for your widget directly, instead of just arranging child widgets. For instance, a Gtk::Label draws the text of the label, but does not do this by using other widgets.
When deriving from Gtk::Widget, you should override the following virtual methods. The methods marked (optional) need not be overridden in all custom widgets. The base class's methods may be appropriate.
get_request_mode_vfunc(): (optional) Return what Gtk::SizeRequestMode is preferred by the widget.
measure_vfunc(): Calculate the minimum and natural width or height of the widget.
size_allocate_vfunc(): (optional) Position the widget, given the height and width that it has actually been given.
on_realize(): (optional)
on_unrealize(): (optional)
on_map(): (optional)
on_unmap(): (optional)
snapshot_vfunc(): Create a render node, e.g. a Cairo::Context node, and draw on it.
The first 3 methods in the previous table are also overridden in custom containers. They are briefly described in the Custom Containers section.
Class Init and Instance Init Functions
Some GTK functions, if called at all, must be called from the class init function. Some other GTK functions, if called, must be called from the instance init function. If your custom widget must call any of those functions, you can derive a class from Glib::ExtraClassInit and derive your custom class from that class. The custom CSS name example shows how that's done.