Re: signal_button_press_event() not sending signal?



Matthew Ryan Hurne wrote:

First of all, let me hint that I am very new to Gtkmm programming, and
relatively new to C++ programming in general.

I am trying to write a simple program that draws a bezier curve in a
DrawingArea which can be manipulated by clicking and dragging its
control points.

Right now the program draws a curve, but I have not yet successfully
implemented anything to manipulate it.  That's what I'm working on.

I figured I'd start by figuring out how to detect a button click on the
DrawingArea.  I know I'll need to get the coordinates of the mouse
pointer as well.  From reading the tutorial, etc. it seemed that
Widget::signal_button_press_event() is the appropriate method to use.  I
have connected it to a signal handler in my MainWindow class.
Everything compiles fine but the code in my signal handler doesn't seem
to execute.

Here's what code it seems you'd need.
In MainWindow's constructor (curveArea is my DrawingArea):

curveArea.signal_button_press_event().connect(sigc::mem_fun(*this,
&MainWindow::on_curve_button_press_event));

A protected member of MainWindow:

bool MainWindow::on_curve_button_press_event(GdkEventButton* event)
{
        std::cout << "The drawing area was clicked" << std::endl;

        return true;
}

I searched the web for a while trying to find any hints, and was only
able to find something on a mailing list from 2002 that said it was a
bug.  Seems like that wouldn't be relevant anymore.  Any help would be
greatly appreciated.  If you want all my source code, I can attach it in
a future e-mail.  I wasn't sure if that was proper mailing list
etiquette so I figured I'd leave it out in this message.  Oh and one
more thing...I'm having a lot of fun learning all this stuff.  :-)

Matthew Hurne

_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org <mailto:>
http://mail.gnome.org/mailman/listinfo/gtkmm-list

I would suggest you to read http://www.gtkmm.org/docs/gtkmm-2.4/docs/tutorial/html/ch14.html. To detect mouse clicks i would override bool Gtk::Widget::on_button_press_event(GdkEventButton* event) ... For further documentation for the various GdkEvent structs you may look at http://developer.gnome.org/doc/API/2.0/gdk/gdk-Event-Structures.html.

antonio



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