how to get key press event in goocanvasmm



Is it possible to receive key press events in canvas?

The following signal handler is not called inside goocanvas. It compiles fine but it is not called if a key 
is pressed.


Exmaple:


Glib::RefPtr<Goocanvas::Item> root;

class MyCanvas: public Goocanvas::Canvas
{
    double scale = 1;

    bool on_key_press_event( GdkEventKey* event ) override
    {
        std::cout << "on_key_press_event" << std::endl;
        return true;
    }

};

int main(int argc, char* argv[])
{
    Gtk::Main app(&argc, &argv);
    Goocanvas::init("example", "0.1", argc, argv);

    Gtk::Window win;

    MyCanvas m_canvas;
    m_canvas.set_size_request(640, 480);
    m_canvas.set_bounds(0, 0, 800, 800);
    root = m_canvas.get_root_item();

    //--------------------------------

    Glib::RefPtr<Goocanvas::Ellipse> outer = Goocanvas::Ellipse::create( 100,100,20,20);
    outer->property_line_width() = 5;
    outer->property_stroke_color() = "red";
    outer->property_fill_color()="blue";
    root->add_child( outer );

    win.add( m_canvas);
    win.show_all_children();


    Gtk::Main::run(win);
    return 0;
}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]