Object Hierarchy:

Object hierarchy for ColorButton


The ColorButton is a button which displays the currently selected color and allows to open a color selection dialog to change the color.

It is suitable widget for selecting a color in a preference dialog.

CSS nodes

GtkColorButton has a single CSS node with name button. To differentiate it from a plain Button, it gets the .color style class.


Example: ColorButton:

public class Application : Gtk.Window {
public Application () {
// Prepare Gtk.Window:
this.title = "My Gtk.ColorButton";
this.window_position = Gtk.WindowPosition.CENTER;
this.destroy.connect (Gtk.main_quit);

// The button:
Gtk.ColorButton button = new Gtk.ColorButton ();

// Use alpha channel
button.set_use_alpha (true);

// Set value to blue:
Gdk.RGBA rgba = Gdk.RGBA ();
bool tmp = rgba.parse ("#0066FF");
assert (tmp == true);

button.rgba = rgba;

// Sets the title for the color selection dialog:
button.set_title ("Select your favourite color");

// Catch color-changes:
button.color_set.connect (() => {
uint16 alpha = button.get_alpha ();
print ("%s, %hu\n", button.rgba.to_string (), alpha);
this.add (button);

public static int main (string[] args) {
Gtk.init (ref args);

Application app = new Application ();
app.show_all ();
Gtk.main ();
return 0;

valac --pkg gtk+-3.0 Gtk.ColorButton.vala

Namespace: Gtk
Package: gtk+-3.0



Creation methods:



Inherited Members:

All known members inherited from class Gtk.Bin
All known members inherited from class Gtk.Widget
All known members inherited from interface Atk.Implementor
All known members inherited from interface Gtk.ColorChooser