LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Gtkmm - signal_button_press_event() not sending signal? (https://www.linuxquestions.org/questions/programming-9/gtkmm-signal_button_press_event-not-sending-signal-268048/)

matthurne 12-19-2004 10:41 AM

Gtkmm - signal_button_press_event() not sending signal?
 
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):
Code:

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

A protected member of MainWindow:
Code:

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, let me know.

Lastly, my development environment:

Fedora Core 3
gcc 3.4.2
gtk 2.4.14
glib 2.4.8
libsigc++ 2.0.6
glibmm 2.4.5
gtkmm 2.4.8

Matthew Hurne

Mara 12-19-2004 02:38 PM

Don't know if gtkmm is much different at this place than pure gtk (that's what I use), but I use that sequence (modified, of course):
Code:

gtk_signal_connect (GTK_OBJECT (drawingArea),
    "button_press_event", (GtkSignalFunc) drawing_button_press_event, NULL);
gtk_widget_set_events (drawingArea,
    GDK_BUTTON_PRESS_MASK);

So I do not only connect the signal but also use *set_events. Remember that drawingArea is different than other widgets at many points.


All times are GMT -5. The time now is 04:45 AM.