Re: RESOLVED: signal_button_press_event() not sending signal?



Matthew Ryan Hurne wrote:

On Sun, 2004-12-19 at 21:49 -0500, Matthew Ryan Hurne wrote:
On Mon, 2004-12-20 at 02:49 +0100, Antonio Coralles wrote:
> Matthew Ryan Hurne wrote:
>
> > On Sun, 2004-12-19 at 22:59 +0100, Antonio Coralles wrote:
> >> 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:> <mailto:> <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
> >> _______________________________________________
> >> gtkmm-list mailing list
> >> gtkmm-list gnome org <mailto:> <mailto:>
> >> http://mail.gnome.org/mailman/listinfo/gtkmm-list
> >
> > Thanks for the tip on reading chapter 14, though I've already
done that.
> > I have been able to draw the curve, control points, and lines
connected
> > the control points just fine. I haven't coded the interaction
between
> > the mouse and the curve, that's where I'm at now.
> >
> > Thanks a TON for the link to the GDK event structures. Though
right now
> > I can't use it because it seems the mouse clicks aren't even being
> > "detected", it will definitely be important when it comes to checking
> > the mouse position and whether a control point has been clicked.
> >
> > I did what you suggested, or at least what I think you suggested,
with
> > no results.  I have inherited my own class, called CurveArea, from
> > DrawingArea.  I overloaded its on_button_press_event(GdkEventButton
> > *event) member with the following:
> >
> > bool CurveArea::on_button_press_event(GdkEventButton* event)
> > {
> >         if (event->type == GDK_BUTTON_PRESS && event->button == 1) {
> >                std::cout << "The drawing area was clicked"
> >                           << std::endl;
> >         }
> >
> >         return true;
> > }
> >
> > Here is the relevant line in CurveArea's constructor:
> >
> >
        this->signal_button_press_event().connect(sigc::mem_fun(*this,
> > &CurveArea::on_button_press_event));
> >
> > I'm guessing I don't need the this->, but I figured being explicit
> > couldn't hurt.
> >
> Yes, you don't need it ....
>
> > When clicking on the CurveArea, nothing is printed to the console.
> > Help! Ahh!
>
> Maybe you've put your drawing area into a widget which doesn't
receive X
> events
> [
http://www.gtkmm.org/docs/gtkmm-2.4/docs/tutorial/html/ch12.html ]. A
> Gtk::EventBox might help ...
> By the way: are you working in windows or linux ?

I have my CurveArea inside a VBox (the top of the VBox contains a
MenuBar).  So then, if I put a widget that does receive X events inside
one that doesn't, then it no longer will either?  Is there some kind of
layer logic going on?  I'm going to try an EventBox...

I am using Linux, by the way.  Sorry I never put any of the important
info in my first e-mail, i.e. using gtkmm-2.4, etc.

>
> >
> > Oh, by the way, why does on_button_press_event have to return a bool?
>
> To be honest, i'm not sure about this myself; as far as I know,
> returning true indicates that the event has been handled ....
>
> antonio
> _______________________________________________
> gtkmm-list mailing list
> gtkmm-list gnome org <mailto:>
> http://mail.gnome.org/mailman/listinfo/gtkmm-list


Ok, I found the solution!  It was related to what you suggested but not
quite.  I took the MenuBar and VBox out of my program to see if a widget
which accepts events (like DrawingArea) won't get them when its inside a
widget that doesn't.  It still didn't work.  In looking at Chapter 12,
however, I noticed the method set_events(Gdk::EventMask events).  This
method is used with EventBox's to set which events the EventBox will
receive.  The description said: "Keep in mind that different widgets
have different default event masks".  This made me think, perhaps
Gdk::BUTTON_PRESS_MASK is not part of DrawingArea's default event mask.
I checked to see if DrawingArea had the set_events() method, and it
does. I used the method on my CurveArea, and it detected the clicks and
my signal handler was called.  The description for set_events() also
notes that set_events() completely overrides the default event mask,
which may cause strange behavior of the widget.  add_events(), however,
adds the Gdk::EventMask you pass it to the current EventMask of the
widget.  So I'm using that method, I'm sure it is preferrable for this
situation.  Anyway, thanks a ton for the help, and maybe I helped you
learn a bit too?  :-)

Glad to hear that it works now; by the way: yes, i learned something too, and that's good, at least for me, and maybe also for the programm i'm working on ... :-)
have a nice day,
                           antonio

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





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