ColorSelectionDialog
The ColorSelectionDialog allows the user to choose a color.
- 16.3.1. Ejemplo
16.3.1. Ejemplo
File: examplewindow.h (For use with gtkmm 3, not gtkmm 2)
#ifndef GTKMM_EXAMPLEWINDOW_H #define GTKMM_EXAMPLEWINDOW_H #include <gtkmm.h> class ExampleWindow : public Gtk::Window { public: ExampleWindow(); virtual ~ExampleWindow(); protected: //Signal handlers: void on_button_color_set(); //Child widgets: Gtk::VBox m_VBox; Gtk::ColorButton m_Button; Gtk::DrawingArea m_DrawingArea; //To show the color. Gdk::RGBA m_Color; }; #endif //GTKMM_EXAMPLEWINDOW_H
File: examplewindow.cc (For use with gtkmm 3, not gtkmm 2)
#include "examplewindow.h" #include <iostream> ExampleWindow::ExampleWindow() { set_title("Gtk::ColorButton example"); set_default_size(200, 200); add(m_VBox); m_VBox.pack_start(m_Button, Gtk::PACK_SHRINK); m_Button.signal_color_set().connect(sigc::mem_fun(*this, &ExampleWindow::on_button_color_set) ); //Set start color: m_Color.set_red(0); m_Color.set_blue(1); m_Color.set_green(0); m_Button.set_rgba(m_Color); m_DrawingArea.override_background_color(m_Color); m_VBox.pack_start(m_DrawingArea); show_all_children(); } ExampleWindow::~ExampleWindow() { } void ExampleWindow::on_button_color_set() { //Store the chosen color, and show it: m_Color = m_Button.get_rgba(); m_DrawingArea.override_background_color(m_Color); }
File: main.cc (For use with gtkmm 3, not gtkmm 2)
#include "examplewindow.h" #include <gtkmm/main.h> int main(int argc, char *argv[]) { Gtk::Main kit(argc, argv); ExampleWindow window; //Shows the window and returns when it is closed. Gtk::Main::run(window); return 0; }